Hello all,
Interested in doing some client side form validation and wanted to use the jQuery.validator plugin. I would also like to activate this validation programatically rather than with a submit button. I believe I am missing something fundamental, since I am unable to get the form to ever tell me it failed. Below is a simple test case of what I am trying to achieve:
<html>
<head>
<title>test validation</title>
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.22.custom.min.js"></script>
<script type="text/javascript" src="js/jquery.validate.min.js"></script>
<script type="text/javascript" >
jQuery.validator.setDefaults({
debug: true,
success: "valid"
});
</script>
<script type="text/javascript" >
$(document).ready(function(){
$("testform").validate({
rules: {
x: {
required: true,
range: [0, 127]
},
y: { "required" }
}
});
});
</script>
</head>
<body>
<div>
<form id="testform" method="get" action="">
<fieldset>
<label for x>X</label>
<input id="x" name="x" size="5" type="text" /><br/>
<label for y>Y</label>
<input id="y" name="y" size="5" type="text" /><br/>
<button id="testformgo">go</button>
<input type="submit" value="submit" /><br/>
</fieldset>
</form>
</div>
<script type="text/javascript" >
$("#testformgo").button().click(function(){
valid = $("#testform").validate().form();
alert(valid);
});
</script>
</body>
</html>
The submit always works and the “go” button always alerts “True” regardless of blanks in the “y” input or out of range values in the “x” input. Does anyone see what I am doing wrong?
Regards,
Jason