Validate jQuery UI MultiSelect Widget

514 Views Asked by At

I know this is a repeated questions but all previously asked question's answer did not worked for me.

I've used this widget but after applying it to all dropdown I'm not being able to validate this new multiselect dropdown.

HTML

<td style="width: 20%; text-align: right;" class="LabelText">
    Select Period* :
</td>
<td style="text-align: left; width: 30%" class="LabelText">
<asp:DropDownList ID="ddlStudyPeriod" runat="server" Width="40px" multiple="multiple">
</asp:DropDownList>
</td>

JavaScript

function fnValidateStudy() {
    var options = $('#ddlStudyPeriod > option:selected');
    debugger;
    if (options.length == 0) {

        alert("Please Select Period");
        return false;
    } 

But this does not work. Even if I've selected values in widget's dropdown its showing blank array in console or 0 length.

I want to check that either any value is selected for dropdown or not.

1

There are 1 best solutions below

0
On

You can do like this.

 var options = $("#ddlStudyPeriod option:selected").length;
        if (options == 0) {
            alert('Please select Period');
            return false;
        }