I am trying to validate user input in a form instantly using jquery. I have written this segment, but actually it doesn’t do what I want. I suppose that it should show a message if the user doesn’t agree. Moreover, it was working properly for a period, but then it doesn’t work. thank you for your help.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Form</title>
<script src="lib/jquery.js" type="text/javascript"></script>
<script src="lib/jquery.metadata.js" type="text/javascript"></script>
<script src="jquery.validate.js" type="text/javascript"></script>
<script type="text/javascript">
$.metadata.setType("attr", "validate");
$(document).ready(function() {
$("#form1").validate({
messages: {
checkbox1: {required: 'you must agree'}
}
}
);
});
</script>
</head>
<body>
<div id="apDiv1">
<h1 style="text-align:center">STEP ONE</h1>
</div>
<form id="form1" action="action.php" method="post">
Enter Your Number
<label>
<input name="textfield1" type="text" id="textfield1" />
</label>
<p/>
I agree
<input type="checkbox" name="checkbox1" id="checkbox1" validate="required:true"/>
<p/>
<input type="submit" name="submit" value="Next" />
</form>
</body>
</html>
Finally, it’s been solved.Here is what I did exactly:
I moved the lib folder to the upper directory so the associated tags would look like this
also I put the file jquery.validate.js one level up, and the script will be:
Actually, I don’t know what is the problem with directories, but It works in this manner.
Thanks you for your answers and comments.