Detect if an element is selected in listbox or not through jquery
I have a multiselect listbox and before submit开发者_如何学运维ting the form i want to check whether user select any option or not through jquery
You could use the .val()
function to get the selected values. For a multi select it returns an array of the selected values or null if no element has been selected:
if ($('#idofselect').val() != null) {
// user has selected at least one value
}
Does this work for you:
$("#formID").submit(function()
{
var selectValue = $('#selectList').val();
if(selectValue != null)
{
// blah
}
});
$('#list option:selected').length
Will get the amount of selected objects i think. (replace '#list' with your selector obviously).
精彩评论