2011-02-06 20 views
14

Ho scritto una funzione jQuery attualmente in esecuzione su Click Event. Devo cambiarlo in modo che venga eseguito quando viene modificato un valore a discesa (Seleziona-Opzione). Qui è il mio codice:Esegui la funzione jQuery al menu a tendina cambia

<form id="form1" name="form1" method="post" action=""> 
    <label> 
    <select name="otherCatches" id="otherCatches"> 
     <option value="*">All</option> 
    </select> 
    </label> 
</form> 

$("#otherCatches").click(function() { 
    $.ajax({ 
     url: "otherCatchesMap.php>", 
     success: function(msg) { 
      $("#results").html(msg); 
     } 
    }); 
}); 
+3

So che questo tipo di commenti sono disapprovati, tuttavia: il googling per 'jquery change' ti avrebbe dato il link alla funzione' change() 'come prima hit: http://api.jquery.com/change/ –

risposta

33

Uso change() invece di click():

jQuery(document).ready(function(){ 
    $("#otherCatches").change(function() { 
    $.ajax({ 
    url: "otherCatchesMap.php>", 
    success: function(msg){ 
     $("#results").html(msg); 
    } 
    }); 
    }); 
}); 
+2

.change() è ottimo per