[英]jquery validation is not working . It is not validating
Below is attached source code of JSP page. 下面是JSP页面的源代码。 I dont know why my validation framework is not working ?
我不知道为什么我的验证框架不起作用?
Can Any Body help me out with there prior experience. 任何身体都可以帮助我帮助您获得以前的经验。
Whenever i am trying to hit on submit button without clicking selection radio buttons. 每当我尝试单击“提交”按钮而不单击选择单选按钮时。 it should give me validation problem .
它应该给我验证问题。 But it is not working.
但这是行不通的。
Dont what gone wrong in my script? 我的脚本出了什么问题?
Can you please review it and help me out? 您可以查看一下并为我提供帮助吗?
HTML Code : HTML代码:
<form method="post" id="identityVerification">
<div class="error-message" id="error-message1" style="display:none;">
<p id="err_cars" style="font-size:13px;"></p>
<p id="err_street" style="font-size:13px;"></p>
</div><br/>
<div>
<p style="padding-bottom:15px; font-size:13px;">Which of the following car is registered under your name in state of Washington?</p>
<input type="radio" name="questions[0].answer" value="Ford Focus" id="questions[0].answer_0"></input>
<label for="questions[0].answer_0">Ford Focus</label>
<input type="radio" name="questions[0].answer" value="Chevy Aveo" id="questions[0].answer_1"></input>
<label for="questions[0].answer_1">Chevy Aveo</label>
<div class="clear"></div>
<input type="radio" name="questions[0].answer" value="Toyota Celica" id="questions[0].answer_2"></input>
<label for="questions[0].answer_2">Toyota Celica</label>
<input type="radio" name="questions[0].answer" value="None of these" id="questions[0].answer_3"></input>
<label for="questions[0].answer_3">None of these</label>
<div class="clear"></div>
</div>
<br/><br/><br/><br/>
<div>
<p style="padding-bottom:15px; font-size:13px;">Which of the following street are you currently residing or have previously resided?</p>
<input type="radio" name="questions[1].answer" value="1 Grape Vine" id="questions[1].answer_0"></input>
<label for="questions[1].answer_0">1 Grape Vine</label>
<input type="radio" name="questions[1].answer" value="23 Main Street" id="questions[1].answer_1"></input>
<label for="questions[1].answer_1">23 Main Street</label>
<div class="clear"></div>
<input type="radio" name="questions[1].answer" value="87 Market Street" id="questions[1].answer_2"></input>
<label for="questions[1].answer_2">87 Market Street</label>
<input type="radio" name="questions[1].answer" value="None of these" id="questions[1].answer_3"></input>
<label for="questions[1].answer_3">None of these</label>
<div class="clear"></div>
</div>
<br/><br/><br/><br/>
<input type="submit" class="ButtonFirst" value="Submit" id="submitVerifyButton">
</form>
JavaScript Code : JavaScript代码:
$(document).ready(function()
{
validationRules = {
"cars": {required:true},
"street": {required:true}
},
validationMessages = {
"cars": "Please select car registered under your name",
"street": "Please select your residential street"
};
$("#identityVerification").validate(
{
rules: validationRules,
messages: validationMessages,
highlight: function(element) {
var id = element.id,
errorElement = $("#err_" + id),
errorContainer = errorElement.closest("div.error-message");
$(element).addClass("error-message");
errorContainer.show();
},
unhighlight: function(element) {
var id = element.id;
$(element).removeClass("error-message");
},
success: function(errorElement)
{
var errorContainer = errorElement.closest("div.error-message");
if(errorContainer.find("span:visible").length == 0)
errorContainer.hide();
},
errorElement: "span"
});
});
So I tested your code and I have to say that your code works fine. 因此,我测试了您的代码,不得不说您的代码运行良好。 You just made a small mistake.
您只是犯了一个小错误。 Take a look to your HTML code and you will find something like this:
看一下您的HTML代码,您会发现类似以下内容:
<input type="radio" name="questions[1].answer" value="1 Grape Vine" id="questions[1].answer_0"></input>
The input fields has got the name questions 1 .answer and questions[0].answer . 输入字段的名称为问题1 .answer和问题[0] .answer 。 In your javascript code, you declared the radio groups with names of
*street* and *cars*
as required. 在您的JavaScript代码中,您根据需要声明了名称为
*street* and *cars*
的无线电组。 So it points to undefined fields in your form. 因此它指向表单中未定义的字段。 Jquery doesn't annoying the user with an undefined error message, so it seemed that your script doesn't work.
jQuery不会用未定义的错误消息来烦扰用户,因此您的脚本似乎无法正常工作。
I guess you haven't included jquery.validation.js file in your layout/page. 我想您尚未在布局/页面中包含jquery.validation.js文件。 Try include the js file.
尝试包括js文件。 If you are not using jquery.validation then you should use this for client-side validation.
如果您不使用jquery.validation,则应将其用于客户端验证。 Checkout following link for more details.
查看以下链接以了解更多详细信息。 http://docs.jquery.com/Plugins/Validation
http://docs.jquery.com/插件/验证
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.