Go Back  HTML Forums - Free Webmaster Forums and Help Forums > WEBSITE DEVELOPMENT > Client Side Scripting
User Name:
Password:
 

Reply
Thread Tools   Display Modes
  View First Unread
 
Old 10-22-2009, 01:21 PM
  #1
jim255
Aspirant (Level 2)
 
Join Date: Oct 2009
Posts: 12
iTrader: (0)
jim255 is an unknown quantity at this point
Javascript

Hi guys im using this code, which works fine but im having difficulty in making it work for multiple drop down boxes.

<head>
<title></title>
<script language="JavaScript">
<!--
function jumpTo() {
var list = document.navList.subMenu
if (list.options[list.selectedIndex].value != "home") {
location = list.options[list.selectedIndex].value
}
}
// -->
</script>

</head>

<body>
<form name="navList">
<select name="subMenu" onChange="jumpTo()">
<option value="home">
<option value="http://www.google.com">Front
<option value="page2.html">Middle
<option value="page3.html">Last
</select>
</form>

</body>

</html>

I want it so that I can add another drop down box and the javascript will cover that aswell and make it function in the way the first box does.
jim255 is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 10-22-2009, 02:32 PM
  #2
coothead
~ bald headed old fart ~
 
coothead's Avatar
 
Join Date: Aug 2003
Location: chertsey, a small town 25 miles south west of london, england.
Posts: 7,922
iTrader: (0)
coothead is a splendid one to beholdcoothead is a splendid one to beholdcoothead is a splendid one to beholdcoothead is a splendid one to beholdcoothead is a splendid one to beholdcoothead is a splendid one to beholdcoothead is a splendid one to behold
Hi there jim255,

this method will work for an infinite number of select elements...
Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="language" content="english"> 
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">

<title></title>

<script type="text/javascript">

function goThere(){
   sel=document.forms[0].getElementsByTagName('select');
for(c=0;c<sel.length;c++) {
sel[c].onchange=function() { 
if(this.value!='') {
   location.href=this.value;
    }
   }
  }
 }

if(window.addEventListener){
   window.addEventListener('load',goThere,false);
 }
else { 
if(window.attachEvent){
   window.attachEvent('onload',goThere);
  }
 }
</script>

</head>
<body>

<form action="#">

<div>

<select>
 <option value="">---options---</option>
 <option value="http://www.google.com">Front</option>
 <option value="page2.html">Middle</option>
 <option value="page3.html">Last</option>
</select>

<select>
 <option value="">---options---</option>
 <option value="http://www.yahoo.com">yahoo</option>
 <option value="http://www.htmlforums.com">HTML Forums</option>
 <option value="http://www.bbc.co.uk">The BBC</option>
</select>

</div>

</form>

</body>
</html>
__________________
coothead is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 10-22-2009, 04:42 PM
  #3
jim255
Aspirant (Level 2)
 
Join Date: Oct 2009
Posts: 12
iTrader: (0)
jim255 is an unknown quantity at this point
Ive tried it and it works great, thanks a lot
jim255 is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 10-22-2009, 05:00 PM
  #4
coothead
~ bald headed old fart ~
 
coothead's Avatar
 
Join Date: Aug 2003
Location: chertsey, a small town 25 miles south west of london, england.
Posts: 7,922
iTrader: (0)
coothead is a splendid one to beholdcoothead is a splendid one to beholdcoothead is a splendid one to beholdcoothead is a splendid one to beholdcoothead is a splendid one to beholdcoothead is a splendid one to beholdcoothead is a splendid one to behold
No problem, you're welcome.
__________________
coothead is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote

Reply
KEEP TABS
SPONSORS
 
Boxedart
 
 


 
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
  
 
 
 



 
  POSTING RULES
 
 
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Thread Tools
Display Modes

Forum Jump

 

All times are GMT -5. The time now is 09:03 PM.

   

Mascot team created by Drawshop.com

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.

Server Monitoring by ENIACmonitor 0.01
HTMLforums.com © Big Resources, Inc. Web Design by BoxedArt.com
vRewrite 1.5 beta SEOed URLs completed by Tech Help Forum and Chalo Na.