开发者

jquery.validate func improper once validateions given in class

Only last element which is given as required is validated [Other elements are not validated while form submission]

$().ready(function(){
    $("#feed").validate();
}); 

Form:

<form name="feed" id="feed" action="feed.php">                                                              
    <table cellpadding="0" cellspacing="0" border="0" class="primaryTable" width="100%">
        <tr>
            <td><label>Name</label></td>
            <td><input type="text" class="inputField {required: true}" /></td>
        </tr>
        <tr>
            <td><label>Email</label></td>
            <td><input type="text" class="inputField {required: true}" /></td>
       开发者_运维知识库 </tr>
        <tr>
            <td><label>Title</label></td>
            <td><input type="text" class="inputField {required: true}" /></td>
        </tr>
    </table>
</form>

If there is any wrong in usage please notify me. Thanks in advance.


You need to specify the name attribute for your inputs to be picked up by the validator (I would recommend specifying id as well and using the for attribute on labels). Also, you should just use class="required" to designate a form field as required:

<form name="feed" id="feed" action="feed.php">                                 
    <table cellpadding="0" cellspacing="0" border="0" class="primaryTable" width="100%">
    <tr>
        <td><label>Name</label></td>
        <td><input name="name" type="text" class="required" /></td>
    </tr>
    <tr>
        <td><label>Email</label></td>
        <td><input name="email" type="text" class="required" /></td>
    </tr>
    <tr>
        <td><label>Title</label></td>
        <td><input type="text" name="title" class="required" /></td>
    </tr>
    </table>
</form>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜