Get Id From Select Box February 10, 2023 Post a Comment I have multiple select boxes whithin a form like this: Solution 1: Use this keyword and change your selector to $('#form select') Demo $(document).ready(function() { $('#form select').change(function() { var strChosen = $(this).attr('id'); alert(strChosen); }); }); Copy Note: You can also use .on() method for change event like $('#form select').on('change',function() {}); Copy For more information on the syntax, you can refer @sbaaaang's answer Solution 2: $(function(){ $('select').on('change',function(){ var id = $(this).attr('id'); alert(id); }); }); Copy Solution 3: $('select').change(function() { alert($(this).attr('id')); }); Copy Solution 4: Register the change handler for the select element then inside the handler use this.id to get the id of the select element $(document).ready(function () { $('#form select').change(function () { var strChosen = this.id; alert(strChosen); }); }); Copy Demo: Fiddle Solution 5: You are using .change() event on form. That's wrong. Use select element with change event like below. $(document).ready(function() { $('select').change(function() { var strChosen = $(this).attr('id'); alert(strChosen); }); Copy Here is the working demo : http://jsfiddle.net/n46Be/ Share Post a Comment for "Get Id From Select Box"
Post a Comment for "Get Id From Select Box"