View Full Version : Only my first JS dropdown menu is working...

08-22-2008, 09:23 PM
I found this simple DD code, that allows a user to select an option and not need a submit button. I have 6 DD menus, but only the first is working. I have separated all functions into separate external .js files, and have a call to all of them in the head of my page. You can view the source code here http://www.kidsfirstweecycling.com ,it is the splash page.

Since I have 6 dd menus, I created 6 individual .js files. They all read the same with only the "city name" being changed throughout. In the example below the city name is "corona"... in the other 5 files it is changed to the other city names.

function coronanav()
var w = document.coronaform.coronalist.selectedIndex;
var url_add = document.coronaform.coronalist.options[w].value;
window.location.href = url_add;

I think it must be something simple, but since I am not fluent, I must be missing it.


08-22-2008, 10:55 PM
It's because your function is only effecting one form element. You'll need something more like this

function coronanav(el)
var w = document.coronaform.el.selectedIndex;
var url_add = document.coronaform.el.options[w].value;
window.location.href = url_add;

where "el" is the name of the form element that you want it to effect you would call it like this

coronanav(element_name)// this would replace your old function