Tuesday 15 January 2013

javascript - How to fire onchange event of combobox? -



javascript - How to fire onchange event of combobox? -

i have combobox, how fire onchange event of combobox , selected value it.

here code did till :

<select name="g1" id="select_g1"> <option value="one">one</option> <option value="two">two</option> <option value="three">three</option> </select> <script> $(document).ready(function(){ $("select_g1").change(function(){ alert("handled"); // alert not fired ... }); }); </script>

edit : if have more 1 combobox :

<select name="g2"> <option value="one">one</option> <option value="two">two</option> <option value="three">three</option> </select>

also disable value selected in combobox g1 in combobox g2.

could please tell me wrong code.

rather trying utilize .change event, please seek utilize .on event.

you can seek utilize such:

$('#select_g1').on('change', function (e) { var optionselected = $("option:selected", this); var valueselected = this.value; alert(valueselected); });

see here -> http://jsfiddle.net/ocrozmkn/

edit :

with respect edited question, can seek next jquery :

$('select').on('change', function (e) { $('select option').prop('disabled', false); var optionselected = $("option:selected", this); var valueselected = this.value; alert(valueselected); $("select option:contains('" + valueselected + "')").attr("disabled","disabled"); });

see here ->http://jsfiddle.net/ocrozmkn/1/

demo multiple comboboxes

see here -> http://jsfiddle.net/ocrozmkn/6/

hope helps!!!

javascript jquery combobox

No comments:

Post a Comment