I have many drop down boxes with the name emp .so in the below code i am trying to print the id of the boxes but some how it is printing empty what am i doing wrong here
var selected_emp = $('select[name="emp"]');
selected_emp.children('option:selected').each(function() {
if($(this).val() != '' && $(this).val() != null)
{
alert($(this).attr('id'));
}
});
Do your option elements have an
idattribute? Typically,optionelements just have a value and the included text. You could do something like this to print the id of the box and the selected value in the box:Or, to just iterate through the select boxes themselves: