Get Id From Select Box March 12, 2024 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); }); }); CopyNote: You can also use .on() method for changeevent like $('#form select').on('change',function() {}); CopyFor more information on the syntax, you can refer @sbaaaang's answerSolution 2: $(function(){ $('select').on('change',function(){ var id = $(this).attr('id'); alert(id); }); }); CopySolution 3: $('select').change(function() { alert($(this).attr('id')); }); CopySolution 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); }); }); CopyDemo: FiddleSolution 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); }); CopyHere 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"