PDA

View Full Version : Multiple Combo Boxes independent of each other.


diving_gal_lmtd
07-24-2005, 08:55 AM
I'm trying to get multiple combo boxes, working independently of each other, to work on one page. The item selected from any combo box should direct the user to a specific area of text using a bookmark.

No matter what I've tried, I can only get 1 combo box to work correctly. If an item is selected from another combo box, it simply directs the user to the last bookmark selected from the "working" combo box, or if no items were previously selected, it takes you to the first item's bookmark from the "working" combo box.

Example: Combo boxes A, B and C, each with 5 items bookmarked as #A1, #A2, ..#B1, #B2...#C1, #C2...etc. Combo box A works flawlessly, if you select item #A4, then select item #B3, it will take you back to #A4. If you then select #A2 it works fine, select #C1 and it goes back to #A2. If no items in "A" were selected, it takes you to #A1.

I know I must be missing an important detail, but I can't figure it out. Any help would be greatly appreciated. Here is a sample from the 1st 3 combos.

<form name="jumpy">


<script language="javascript">
<!--

/*Jumpy combo box credit:
JavaScript Kit (www.javascriptkit.com)
Over 200+ free JavaScripts here!
*/

function gone()
{
location=document.jumpy.example.options[document.jumpy.example.selectedIndex].value
}
//-->
</script>

<b><a href="#A">A. What is MonkeyRoyale? </a></b><br>


<select name="example" size="1" onChange="gone()">
<option value="#A1">What is MonkeyRoyale?</option>
<option value="#A2">What are the requirements for being a member of MonkeyRoyale?</option>
<option value="#A3">Is it free to join?</option>
<option value="#A4">Can I use AOL with MonkeyRoyale?</option>
</select>
<input type="button" name="test" value="Go!"
onClick="gone()">



<p> <b><a href="#B">B. Creating an Account.</a></b><br>


<select name="example2" size="1" onChange="gone()">
<option value="#B1">How do I register?</option>
<option value="#B2">Why do you need my personal information? Will this information be kept private?</option>
<option value="#B3">I messed up when I made my account and the name is wrong. Should I just make a new account with the right name?</option>
<option value="#B4">Can other members of my family join?</option>
<option value="#B5">Can I also join Royal Pogo Monkeys and Jungle Monkeys on Yahoo?</option>
<option value="#B6">Do I need to use the same ID for all divisions?</option>
</select>
<input type="button" name="test" value="Go!"
onClick="gone()">

</p>



<p><b><a href="#C">C. Getting Started.</a></b><br>

<select name="example3" size="1" onChange="gone()">
<option value="#C1">I've registered and signed in, what do I do now?</option>
<option value="#C2">How do I join a league?</option>
<option value="#C3">Can I join more than 1 league?</option>
<option value="#C4">How can I see the upcoming tourneys in my league?</option>
<option value="#C5">How do I remove a league from the My Leagues list?</option>
</select>
<input type="button" name="test" value="Go!"
onClick="gone()">


Item #A, #B and #C are titles for each corresponding combo box and are linked separately to bookmarks.

shyam
07-24-2005, 10:21 AM
your code can only work for the first combo box because u've a single function gone() which jumps to the location given in the combo box "example". so if u want the others to run as well u must write additional functions gone2() and gone3() which do the same for example2 and example3.

or, you can pass the combo to be jumped
example
<select name="example2" size="1" onChange="gone(this)">
and write the function thus
function gone(combo) {
location=combo.options[combo.selectedIndex].value;
}

jscheuer1
07-24-2005, 10:36 AM
In order to get this to work, you need to pass the function gone() a variable that will tell it which combo box it is supposed to be dealing with. Call gone() with the name of the combo box, for instance:

onclick="gone('example')"

and/or:

onchange="gone('example2')"

Rewrite the function gone() to reflect this:
function gone(exmpl)
{
location=document.jumpy[exmpl].options[document.jumpy[exmpl].selectedIndex].value
}

jscheuer1
07-24-2005, 10:49 AM
<select name="example2" size="1" onChange="gone(this)">That is all well and good (with your updated gone(combo) function) but, will not work for the onclick events. If however you use the name of the select box without quotes:
onclick="gone(example#)"where # is the number of the select example (or nothing for the first one) that will achieve the expected result.

shyam
07-24-2005, 11:01 AM
yes thats right. cannot pass the *this* value for clicks. din't get that one :)

Johnny Lang
07-24-2005, 01:15 PM
<HTML>
<Head>
<Script Language=JavaScript>

function gone(nLink){

window.location = nLink;
}

function gone2(nList){

window.location = nList.value;
}


</Script>
</Head>
<Body>
<form name='jumpy'>
<b><a href="#A">A. What is MonkeyRoyale? </a></b><br>


<select name="example" size="1" onChange="gone(this.value)">
<option value="#A1">What is MonkeyRoyale?</option>
<option value="#A2">What are the requirements for being a member of MonkeyRoyale?</option>
<option value="#A3">Is it free to join?</option>
<option value="#A4">Can I use AOL with MonkeyRoyale?</option>
</select>
<input type="button" name="test" value="Go!" onClick="gone2(this.form.example)">



<p> <b><a href="#B">B. Creating an Account.</a></b><br>


<select name="example2" size="1" onChange="gone(this.value)">
<option value="#B1">How do I register?</option>
<option value="#B2">Why do you need my personal information? Will this information be kept private?</option>
<option value="#B3">I messed up when I made my account and the name is wrong. Should I just make a new account with the right name?</option>
<option value="#B4">Can other members of my family join?</option>
<option value="#B5">Can I also join Royal Pogo Monkeys and Jungle Monkeys on Yahoo?</option>
<option value="#B6">Do I need to use the same ID for all divisions?</option>
</select>
<input type="button" name="test" value="Go!" onClick="gone2(this.form.example2)">

</p>



<p><b><a href="#C">C. Getting Started.</a></b><br>

<select name="example3" size="1" onChange="gone(this.value)">
<option value="#C1">I've registered and signed in, what do I do now?</option>
<option value="#C2">How do I join a league?</option>
<option value="#C3">Can I join more than 1 league?</option>
<option value="#C4">How can I see the upcoming tourneys in my league?</option>
<option value="#C5">How do I remove a league from the My Leagues list?</option>
</select>
<input type="button" name="test" value="Go!" onClick="gone2(this.form.example3)">

</form>

</Body>
</HTML>

jscheuer1
07-24-2005, 01:51 PM
Seems like the long way home, Johnny Lang. Should work though.

diving_gal_lmtd
07-24-2005, 01:51 PM
Thank You!!

The suggestions worked GREAT! and I now have 15 working combo boxes!

I just want to say how impressed I am with the speed in which I received helpful suggestions, and how helpful they were!