Noobster Noobster - 5 months ago 20
Javascript Question

Onchange event for multiple dropdowns issue

I have a list like this:

<form>
<select id="List_22" >
<option value="default">Default</option>
<option value="1">Oil</option>
<option value="2">Gas</option>
<option value="3">Power</option>
</select>
<form>


I want to launch a function upon dropdown change, so this works fine:

document.getElementById("List_22").onchange = function() {...


I however have multiple dropdowns that should all use the same function. I have tried to use the below wildcard but it does not work

document.getElementById("[id^=L]").onchange = function() {


What am I doing wrong? I am going slightly barmy. Thank you all for your time.

Answer
    $('form select').on('change', function(){

    // Your code here
    });
Comments