开发者

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;
    }
}
});


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();


"dest_var[]" : {required: true}


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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜