Jquery - If Any Select Within A Div Has A Value
Been having lot's of trouble with this one. Let's say I had the following html:
Solution 2:
You can do this with $.each():
$('#step_1').find('SELECT').each( function() {
if( $(this).val() === 'select one' ) {
alert('Please select yes or no!');
returnfalse;
}
});
Note that returning false will prevent the loop from continuing once a missing field is found.
Solution 3:
Your test fails because length
is not a method. It is a property. Remove the ()
. If you look in your debugger you should see a warning about this.
Also, your selector should be checking the selected option, not the select list itself.
$('#submit').click(function() {
$foo = $('#step_1 select option:selected[value="select one"]');
alert($foo.length);
});
Post a Comment for "Jquery - If Any Select Within A Div Has A Value"