user2876368
user2876368

Reputation: 677

Detect with JQuery when a select changes

I have a Jqgrid which dynamically 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.

I'm trying with:

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

But is not working at all.

Upvotes: 42

Views: 71531

Answers (2)

Corinne Kubler
Corinne Kubler

Reputation: 2092

This should work, be sure you did not forget $(document).ready(function() {

$(document).ready(function() {  
    $('#won').change(function(){
        alert( $(this).find("option:selected").attr('value') );       
    });
 });

Upvotes: 37

Alessandro Minoccheri
Alessandro Minoccheri

Reputation: 35973

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

try this:

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

Upvotes: 98

Related Questions