Reputation: 1133
Here is the dropdown in question:
<select name="data" class="autotime" id="EventStartTimeMin">
<option value=""></option>
<option value="00">00</option>
<option value="10">10</option>
<option value="20">20</option>
<option value="30">30</option>
<option value="40">40</option>
<option value="50">50</option>
</select>
What I want to do is check if the current value is empty:
if ($("EventStartTimeMin").val() === "") {
// ...
}
But it does not work, even though the value is empty. Any help is much appreciated.
Upvotes: 29
Views: 144531
Reputation: 99
You can try this also-
if( !$('#EventStartTimeMin').val() ) {
// do something
}
Upvotes: 9
Reputation: 38112
You need to use .change()
event as well as using #
to target element by id
:
$('#EventStartTimeMin').change(function() {
if($(this).val()===""){
console.log('empty');
}
});
Upvotes: 5
Reputation: 337713
You forgot the #
on the id selector:
if ($("#EventStartTimeMin").val() === "") {
// ...
}
Upvotes: 53