Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if selected dropdown value is empty using jQuery

Tags:

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.

like image 825
Domas Avatar asked Apr 22 '14 12:04

Domas


People also ask

How check dropdown is empty or not in jQuery?

What I want to do is check if the current value is empty: if ($("EventStartTimeMin"). val() === "") { // ... }

How check value is selected or not in jQuery?

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.

How do you check whether dropdown is selected or not?

Use the tagName property to check if an element is a select dropdown, e.g. if (select. tagName === 'SELECT') {} .


1 Answers

You forgot the # on the id selector:

if ($("#EventStartTimeMin").val() === "") {     // ... } 
like image 55
Rory McCrossan Avatar answered Sep 23 '22 15:09

Rory McCrossan