Omega
Omega

Reputation: 9158

Multiple Select validation with jquery

I have this multiple select:

<select id="sel_dest" name="dest_var[]" multiple disabled="disabled" size="10">
<option value="" selected>Destinatario</option>
<option value="1"> .........
</select>

how can i validate (required field) this select with jquery validation plugin?

this code doesn't work:

$("#register_form").validate({
rules: {
    dest_var: {
        required: true;
    }
}
});

Upvotes: 1

Views: 5847

Answers (3)

dejung.kang
dejung.kang

Reputation: 21

"dest_var[]" : {required: true}

Upvotes: 2

tcooc
tcooc

Reputation: 21209

Simply use a required class for the select tag.(and remove the [] in the id)

<select id="sel_dest" name="dest_var" class="required" multiple disabled="disabled" size="10">
<option value="" selected>Destinatario</option>
<option value="1"> .........
</select>

script:

$("#register_form").validate();

Upvotes: 3

Pat
Pat

Reputation: 25675

You can see how to do it on the this example page.

rules: { 
    dest_var: { 
        required: true,
        rangelength:[2,3]
    }
} 

Upvotes: 1

Related Questions