jquery validate plugin
In my case name and id's of form are different and names are of format data[password] so thsi is the solution that i found on net and it works
$开发者_如何学Go(document).ready(function()
{
var passwd = $("#old-password").attr("name");
var $params = {debug:false, rules:{}, messages:{}};
$params['rules'][passwd] = {"required": true, "maxlength": 100};
$params['messages'][passwd] = {"required": "Please Enter Old Password ",'maxlength':'Old Password should not exceed 100 characters'};
$("#GamerAccountSettingsForm").validate($params);
});
This outputs a label with class error but this is what i want it to do. If there is a div with class error-message next to this input field it should show error inside it else it needs to append a div with class error-message to the input field
You can use the errorPlacement options for this http://docs.jquery.com/Plugins/Validation/validate#options
And if I am correct, this should work;
$params['errorPlacement'] = function(error, element)
{
if($(element).next("div.error-message"))
{
$(element).next("div.error-message").html(error.html());
}
else
{
divError = $("<div class='error-message'>" + error.html() + "</div>");
divError.insertAfter(element);
}
};
精彩评论