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.
$(this). find("option:selected"). attr('value') tells you the new "won value" if it is what you are looking for ...
The change() is an inbuilt method in jQuery that is used to detect the change in value of input fields.
Syntax of jQuery Select Option$(“selector option: selected”); The jQuery select option is used to display selected content in the option tag. text syntax is below: var variableValue = $(“selector option: selected”).
Using the jQuery change() method; you can set the selected value of dropdown in jquery by using id, name, class, and tag with selected html elements; see the following example for that: Example 1 :- Set selected value of dropdown in jquery by id.
The problem is that the select are created dynamically, then you need to use .on()
try this:
$(document).on('change','#won',function(){
alert("PROBANDO");
});
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') );
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With