Detect with JQuery when a select changes

user2876368 picture user2876368 · Oct 22, 2013 · Viewed 56.5k times · Source

I have a Jqgrid which dinamically generates selects like this:

    <select id="won" style="width: 65px;">
       <option value="">-WON?</option>
       <option value="1" selected>Bet1</option>
       <option value="2" >Bet2</option>
       <option value="3" >Bet3</option>
    </select>

Each one have a different selected option. I would like to detect when one select changes so I can save it in my database.

Im trying with:

         $('#won').change(function(){
               alert("PROBANDO");
          });

But is not working at all. Any help will be apreciated Thanks.

Answer

Alessandro Minoccheri picture Alessandro Minoccheri · Oct 22, 2013

The problem is that the select are created dynamically, then you need to use .on()

try this:

         $(document).on('change','#won',function(){
               alert("PROBANDO");
          });