开发者

Jquery Form Validation Plugin Not Working

I try to validate a simple Form but the Jquery Validation

Plugin not working wh开发者_运维问答en I use only Button not The Submit

Button. I can not use the Submit button there Because If I use submit

Button After Submitting the form It take the Action and goes

to Default page while my current form is comes from Ajax. I am

very new to Jquery. Please Help its Urgent... I am giving the files here. index.html

<html>
<head>
<script src="jquery.js">
<script="jquery-validate-min.js">
<script="validation.js>
</head>
<body>
<form id="contact_form">
<table>
<tr><th>Name</th><td><input name="name" /></td></tr>
<tr><th>E Mail</th><td><input name="email" /></td></tr>
<tr><th><input type="button" name ="submit" id="form_sub" 

onclick="save"></th><td><input name="email" /></td></tr>
</table>
</form>
</body>
</html>

Now the validation.js file

function save(){

$("#form_sub").click(function(){
$("#contact_form").validate({
'rules':{
'name':{
'required':true,
'minlength':5
},
'email':{
'required':true,
'email':true
}
}
})
}

Everything works fine when we use input type="submit"... But it not working when we use input type="button"

Any Idea how can Fix this? I am new to Jquery ... Please Help


With jQuery, you don't need the onclick. Remove the function save(), {, }, and the onclick parameter.

.click(...) in jquery is the same as onclick, so you are essentially registering another onclick when save() is called.


I am working this too what I ended up doing was I used submit then on the form I did.

Html.BeginForm("", "", FormMethod.Post , new { id = "myFormid", onSubmit="return false;"})

this stops the submit however it doesn't provide the automatic short circuit if the model is invalid.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜