I'm using the below selector to get all the form inputs that are pre-populated with a value.
$('input[value!=""]');
This works great and so I thought I could apply the same logic to my select elements using the following selector, though it seems to be selecting all the select elements in Chrome.
$('select[value!=""]');
Below is an example of two types of selects on the form:
<select name="phone2_type" id="phone2_type">
<option value="">Select one:</option>
<option value="HOME">Home</option>
<option value="CELL">Cell</option>
<option value="BUSN">Business</option>
</select>
<select name="state" id="state">
<option value="">Select one:</option>
<option value="XX">Outside USA/Canada</option>
<option value="AL" selected="selected">Alabama</option>
<option value="AK">Alaska</option>
...
</select>
I'd like to select the second select since it has a value selected already with the select="selected"
value
is not an attribute of select
tag.
So you need to try:
var emptySelect = $('select').filter(function() {
return $.trim( $(this).val() ) == '';
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With