?
Solved

Javascript 'third' dynamic pulldown onChange

Posted on 2003-02-20
3
Medium Priority
?
1,378 Views
Last Modified: 2011-08-18
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
Comment
Question by:skranch
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 4

Accepted Solution

by:
jonnal earned 400 total points
ID: 7990617
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
 
LVL 16

Expert Comment

by:jaysolomon
ID: 10082755
*******************************************************
******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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question