<select name="category" id="category">
<option value="">All Category</option>
<option value="1">Category 1</option>
<option value="2">Category 2</option>
<option value="3">Category 3</option>
</select>
How to choose the category with value=""
Conditions for a correct:
if($('#category option:selected')){
var category_url = "&category="+$('#category').val(); <!-- True -->
}
Condition 2 wrong:
if($('#category option[value=""]')){
var category_url = ""; <!-- Error -->
}
Please help me!!!
if(!$("#category").val())
//selected valule is ""
I am not sure if I understand your question correctly, but are you looking to do something like this?
if($('#category option:selected')){
var selValue = $('#category').val();
var category_url;
if(selValue)
category_url = "&category="+$('#category').val(); <!-- True -->
else
<!-- error -->
}
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