I have not really used JavaScript before but I am trying to validate form elements as they are being filled out. I have an X and a Check mark that I am trying to display next to the field to show if it is valid or not. I know that this is partially right because I can use an alert but I am not sure how to alter the fields of the graphics.
The JavaScript:
function validate_field(field)
{
var value = document.newAccount.fname;
if (value==null||value=="")
{
document.fnameX.visibility = visible;
document.fnameOK.visibility = hidden;
//alert("FAIL");
return false;
}
else
{
document.fnameX.visibility = hidden;
document.fnameOK.visibility = visible;
//alert("TRUE");
return true;
}
}
Some of the HTML:
<form action="XXXXX" method="post" name="newAccount">
<table width="78%" border="0" align="center">
<tr>
<td colspan="2"><strong>Personal Info:</strong> </td>
</tr>
<tr>
<td width="24%"><div align="right">First Name: </div></td>
<td width="76%">
<input type="text" onchange="return validate_field(this)" onfocus="return validate_field(this)" name="fname" tabindex="1" size="50"/>
<img name="fnameX" src="redx.jpg" style="visibility:hidden" alt="X" width="18" height="18" /><img name="fnameOK" src="checkmark.jpg" style="visibility:hidden" alt="Ok" width="18" height="18" /></td>
</tr>
<tr>
<td><div align="right">Last Name: </div></td>
<td><input type="text" name="lname" tabindex="2" size="50"/></td>
</tr>
</table>
</form>