Need a little help with javascript and webpage dropdowns..
September 29, 2006 4:26 AM
Subscribe
Need a little help with javascript..
Say I have a page with multiple dropdown boxes, all of which contain exactly the same options. At the minute, I have to click on all of those dropdowns individually, which is very repetitive.
I was thinking that it might be possible to use javascript to add a button to that webpage that would select the same option on all the dropdowns on that page. But sadly I don't know how to do that, and google is no help.. so any help would be appreciated.
(by the way, it doesn't have to be javascript - I'm happy to do anything that would help do this.)
posted by ascullion to computers & internet (8 comments total)
Well that doesn't make sense at all. But a simple solution would be that when you change the value in one dropdown, it automatically changes the value of others.
add this to your select tags:
onchange="toggleAll(this.value)"And add this in the head in script tags:
function toggleAll(newVal) { var selects = document.getElementsByTagName("select"); for (var i = 0; i < selects.length; i++) {br> for (var x = 0; i < selects[i] .options.length; x++) {br> if (selects[i].options[x].value == newVal) selects[i].options[x].selected = true; } } >>NOTE: Take out the br> that shows up at the end of some lines, that's Metafilter adding those for reasons unknown to me.
posted by furtive at 5:11 AM on September 29, 2006