How to add an onchange event to a select box via javascript?
Add
transport_select.setAttribute("onchange", function(){toggleSelect(transport_select_id);});
setAttribute
or try replacing onChange
with onchange
yourSelect.setAttribute( "onchange", "yourFunction()" );
replace:
transport_select.onChange = function(){toggleSelect(transport_select_id);};
with:
transport_select.onchange = function(){toggleSelect(transport_select_id);};
on'C'hange >> on'c'hange
You can use addEventListener too.
Here's another way of attaching the event based on W3C DOM Level 2 Events Specification:
transport_select.addEventListener(
'change',
function() { toggleSelect(this.id); },
false
);