I have a form with 4 dropdowns. The default option in all drop-down lists is “Please select.” I want to use jquery to make sure all the dropdowns matter before submitting the page, but my code only works on the first. Does anyone have a way that I can immediately check all the drop down lists?
function doconfirm() { if ($('select').val() == '') { alert("Please Select All Fields"); } }
I am sure something is missing, but I cannot figure it out. Thanks
function doconfirm() { if ($('select').each(function() { if($(this).val() == '') { alert("Please Select All Fields"); return(false); } }); }
@mgroves, , , select, . - , (, .val() ):
function doconfirm() { if($('select').each(function() { if(!$(this).find('option:selected').length) { alert("Please Select All Fields"); return(false); } }); }
for a different approach to this, why not use
function doConfirm() { var toReturn = true; if ( $('select').filter( function(){ return $(this).val() === ''; }).length ) { toReturn = false; //notify user } return toReturn; }
$('select').each(function(s){if(!this.val())...});