
how to check if a selection field is selected
By: a guest on
Mar 26th, 2012 | syntax:
None | size: 1.12 KB | hits: 12 | expires: Never
<select class="select" id="quantity" name="quantity">
<option selected="selected" value="">select one</option>
<option value="data1">data1</option>
<option value="data2">data2</option>
<option value="data3">data3</option>
</select>
$(document).ready(function() {
$("#btnaddcart").click(function()
{
if($("input[name=quantity]").val() == null)
{
var data = $(this).val();
alert(data);
}
});
});
if($("input[name=quantity]").val() == null)
if($('#quantity').val() == '')
# not selected
if (!$("#quantity option:selected").length) {
}
$(document).ready(function() {
$("#btnaddcart").click(function(){
var box=document.getElementById('quantity');
var index=box.selectedIndex;
// any one selected apart from the first option
if(index!=0){
var data=box.options[index].value;
alert(data);
}
});
});
$("#btnaddcart").click(function()
{
if($("#quantity").val() == '')
{
alert("cannot be null");
}
else{
alert($(this).val());
}
});