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.
What I want to do is check if the current value is empty: if ($("EventStartTimeMin"). val() === "") { // ... }
Answer: Use the jQuery :selected Selector You can use the jQuery :selected selector in combination with the val() method to find the selected option value in a select box or dropdown list.
Use the tagName property to check if an element is a select dropdown, e.g. if (select. tagName === 'SELECT') {} .
You forgot the #
on the id selector:
if ($("#EventStartTimeMin").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