Ezilon.com - Target Your Audience, be Seen in Your Region

How to have two identical js jump menus?

You are viewing this site as a guest. Join our community to get your questions answered and share knowledge. Active members may advertise and ask for a website critique.

They have: 43 posts

Joined: Sep 2005

I've got a javascript jump menu on my practice site that I want to show in two places on the same page (one at the top of the page, one at the bottom). Problem is, only the bottom one works, even when I change the name and id attributes. What am I missing?
Here's teh code:

<select name="jump1" id="jump1" class="postform">
<option value="-1">Menu Title</option>
<option value="1">First Post</option>
<option value="2">Second Post</option>
</select>

&lt;script lang="javascript"&gt;<!--
var dropdown = document.getElementById("jump1");
function onCatChange() {
if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
location.href = "http://localhost/?p="+dropdown.options[dropdown.selectedIndex].value;
}
}
dropdown.onchange = onCatChange;
-->
&lt;/script&gt;

teammatt3's picture
Moderator

He has: 1,856 posts

Joined: Sep 2003

I changed the name of some stuff, and it works for me:

<select name="jump1" id="jump1" class="postform">
<option value="-1">Menu Title</option>
<option value="1">First Post</option>
<option value="2">Second Post</option>
</select>

&lt;script lang="javascript"&gt;<!--
var dropdown = document.getElementById("jump1");
function onCatChange() {
if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
location.href = "http://localhost/?p="+dropdown.options[dropdown.selectedIndex].value;
}
}
dropdown.onchange = onCatChange;
-->
&lt;/script&gt;

<select name="jump2" id="jump2" class="postform">
<option value="-1">Menu Title</option>
<option value="1">First Post</option>
<option value="2">Second Post</option>
</select>

&lt;script lang="javascript"&gt;<!--
var dropdown2 = document.getElementById("jump2");
function onCatChange() {
if ( dropdown2.options[dropdown2.selectedIndex].value > 0 ) {
location.href = "http://localhost/?p="+dropdown2.options[dropdown2.selectedIndex].value;
}
}
dropdown2.onchange = onCatChange;
-->
&lt;/script&gt;

'

If you use var' outside of a function, the variable is still global.

They have: 43 posts

Joined: Sep 2005

Ah, I see the difference now. Working great, thanks TM3!