Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1413
  • Last Modified:

Javascript 'third' dynamic pulldown onChange

Hi there,

I found the working example below which is ok, but need to add a third pulldown menu that is changed based on the second pulldown menu - see more_examples field:

thanks


<html>
<head>
<script language="javascript">
var dogs = new Array("poodle","puli","greyhound");
var fish = new Array("trout", "mackerel", "bass");
var birds = new Array("robin", "hummingbird", "crow");

function swapOptions(the_array_name)
{
  var numbers_select = window.document.the_form.the_examples;
  var the_array = eval(the_array_name);
  setOptionText(window.document.the_form.the_examples, the_array);
}

function setOptionText(the_select, the_array)
{
  for (loop=0; loop < the_select.options.length; loop++)
  {
    the_select.options[loop].text = the_array[loop];
  }
}
</script>
               
</head>

<body bgcolor="#ffffff">
     
<b>My favorite animal is ...</b>

<form name="the_form">
<select name="choose_category" onChange="swapOptions(window.document.the_form.choose_category.options[selectedIndex].text);">
<option selected>dogs
<option>fish
<option>birds
</select>

<select name="the_examples">
<option>poodle
<option>puli
<option>greyhound      .
</select><select name="more_examples">
<option>poodletypea
<option>poodletypeb
<option>poodletypec
</select>
</form>
          <p></p>
     </body>
</html>
0
skranch
Asked:
skranch
1 Solution
 
jonnalCommented:
hi

try this
any questions post

<html>
<head>
<script language="javascript">
var dogs = new Array("poodle","puli","greyhound");
var fish = new Array("trout", "mackerel", "bass");
var birds = new Array("robin", "hummingbird", "crow");
var poodle = new Array("1 poodle","2 poodle","3 poodle");
var puli = new Array("1 puli","2 puli","3 puli");
var greyhound = new Array("1 greyhound","2 greyhound","3 greyhound");
var trout = new Array("1 trout","2 trout","3 trout");
var mackerel = new Array("1 mackerel","2 mackerel","3 mackerel");
var bass = new Array("1 bass","2 bass","3 bass");
var robin = new Array("1 robin","2 robin","3 robin");
var hummingbird = new Array("1 hummingbird","2 hummingbird","3 hummingbird");
var crow = new Array("1 crow","2 crow","3 crow");

function swapOptions(the_array_name,the_select_name)
{
 var numbers_select = window.document.the_form[the_select_name];
 var the_array = eval(the_array_name);
 setOptionText(window.document.the_form[the_select_name], the_array);
}

function setOptionText(the_select, the_array)
{
 for (loop=0; loop < the_select.options.length; loop++)
 {
   the_select.options[loop].text = the_array[loop];
 }
}
</script>

</head>

<body bgcolor="#ffffff">

<b>My favorite animal is ...</b>

<form name="the_form">
<select name="choose_category" onChange="swapOptions(window.document.the_form.choose_category.options[selectedIndex].text,'the_examples');">
<option selected>dogs
<option>fish
<option>birds
</select>

<select name="the_examples" onChange="swapOptions(window.document.the_form.the_examples.options[selectedIndex].text,'more_examples');">
<option>poodle
<option>puli
<option>greyhound      .
</select><select name="more_examples">
<option>
<option>
<option>
</select>
</form>
         <p></p>
    </body>
</html>
0
 
jaysolomonCommented:
*******************************************************
******PLEASE DO NOT ACCEPT THIS COMMENT AS ANSWER******
*******************************************************
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area:
RECOMMENDATION:

 - [Points to jonnal Grade A]

Please leave any comments here within the next seven days.
*******************************************************
******PLEASE DO NOT ACCEPT THIS COMMENT AS ANSWER******
*******************************************************

jAy
EE Cleanup Volunteer
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now