[thelist] Javascript: onChange fires every time the page loads
Christian Heilmann
codepo8 at gmail.com
Thu Apr 21 11:55:40 CDT 2005
On 4/21/05, Iain Gardiner <iain at firelightning.com> wrote:
> Hi guys,
>
> Warning! JS newbie coming through. I have a problem with attaching
> onchange handlers to menu options. The full script I am referring to is
> at http://www.firelightning.com/js/switcher.js and the specific function
> is this:
> var styleMenu = document.getElementById('styleMenu');
> // Attach an onchange event to each menu option:
You don't need the loop at all. getElementById returns 1 element and
you set the onchange handler on that one.
styleMenu.onchange = function()
{
setStyle(this.options[this.selectedIndex].value]);
}
You also should use a non-Javascript fallback and offer a go button
for that one.
Lastly there is no need for a fieldset around a single dropdown element.
--
Chris Heilmann
Blog: http://www.wait-till-i.com
Writing: http://icant.co.uk/
Binaries: http://www.onlinetools.org/
More information about the thelist
mailing list