jquery - Check whether an item from a dropdown list is selected -
i have multi-select html dropdown list. want check on button click whether there item selected or not. if there no element selected, alert "item not selected" else selected items alert "selected".
if ($("#ddl1 >option").length >= 1) { if ($("#ddl1 >option:selected").val() == 'undefined') { alert("not selected"); } else { alert("deleted"); } } else alert("list empty");
you can use length <= 0
here
if ($("#ddl1 > option").length >= 1) { if ($("#ddl1 > option:selected").length <= 0) { alert("not selected"); } else { alert("deleted"); } } else alert("list empty");
Comments
Post a Comment