I have a problem with jQuery Validator. I want to use the "required" property to enter text. It does not work when input sets a value attribute using HTML code (tested on Firefox (3.5), and on IE 8 it works a bit better on IE).
History: 1. Page loading; 2. The value is cleared; 3. focus is changed. 4. Nothing happens, but an error message should be displayed; 5. Return to the field and enter a few characters. 6. change of focus; 7. return to the field; 8. Cleaning the field. 9. An error is issued even before leaving the field.
HTML code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<script src="Web/Scripts/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="Web/Scripts/jquery.validate.js" type="text/javascript"></script>
</head>
<body>
<form id="form1">
<input type="text" id="name1" name="name1" value="test" /><br />
<input type="text" />
</form>
<script type="text/javascript">
$(document).ready(function() {
var validator = $("form").validate({
rules: {
name1: {
required: true,
minlength: 2
}
},
messages: {
name1: "bad name"
},
});
});
</script>
</body>
</html>
source
share