this is the code (something basic)
Code:
<html>
<head>
<script type="text/javascript">
function validateField(fld) {
var error = "";
var illegalChars = /\W/; // allow letters, numbers, and underscores
if (fld.value == "") {
fld.style.borderColor = 'red';
fld.parentNode.getElementsByTagName("span")[0].innerHTML = "You didn't enter a value.\n";
fld.focus();
return false;
} else if ((fld.value.length < 2) || (fld.value.length > 16)) {
fld.style.borderColor = 'red';
fld.parentNode.getElementsByTagName("span")[0].innerHTML = 'The field is the wrong length.';
fld.focus();
return false;
} else if (illegalChars.test(fld.value)) {
fld.style.borderColor = 'red';
fld.parentNode.getElementsByTagName("span")[0].innerHTML = 'The field contains illegal characters.\n';
fld.focus();
return false;
} else {
fld.style.border = 'none';
fld.parentNode.getElementsByTagName("span")[0].innerHTML = "";
fld.parentNode.getElementsByTagName("span")[1].style.display = "none";
return true;
}
}
</SCRIPT>
</head>
<body>
<form method="post">
<fieldset>
<label for="field1">label1:</label>
<input
type="text"
id="field1"
name="field1"
size="20"
value=""
onfocus='this.parentNode.getElementsByTagName("span")[1].style.display = "inline";'
onblur='return validateField(this);' />
<span style="position:absolute; left:350px; color:red;"></span><br/>
<span class="hint" style="display:none;">
hint 1</span>
</fieldset>
<fieldset>
<label for="field2">label2:</label>
<input
type="text"
id="field2"
name="field2"
size="20"
value=""
onfocus='this.parentNode.getElementsByTagName("span")[1].style.display = "inline";'
onblur='return validateField(this);' />
<span style="position:absolute; left:350px; color:red;"></span><br/>
<span class="hint" style="display:none;">
hint 2</span>
</fieldset>
</form>
</body>
</html>
the 'hint' appears when the field get the focus;
the field border becomes red and the error message appears when the field value doesn't pass the test, but the field looses the focus when an error occurs
the focus should stay in the field until the field value passes the field validation.
what is wron with this code here
some help please,
thx
__________________
Please login or register to view this content. Registration is FREE
Check out the Facebook Clone build with Jcow SNS at Please login or register to view this content. Registration is FREE , it is free and it always will be
|