Forum Moderators: open
When an invalid value is submitted from the form, the name of the input field is entered into a variable called $error_field.
What I want to do is send the value of the variable back to the form and use it to highlight the background color of the input field that the user entered the invalid value into, or maybe display a red asterisk or something to that effect...
Here is the code for the form page:
<html>
<head>
<?
if ($error_field) {
echo "<script type='text/javascript'>\n
document.TheForm.$error_field.style.backgroundColor='#ff0000';\n";
}
?>
</head>
<body>
<form name=TheForm method=post action=script.php>
<input name=FirstField>
<input name=SecondField>
<input type=submit value=Submit>
</form>
</body>
</html>
Here is the code for the script:
<?
if (!$FirstField) {
$error_field="FirstField";
die("
<form method=post>\n
You didnt enter a value into the FirstField field.\n
<input type=hidden name=error_field value=$error_field>\n
<input type=submit value=OK>\n
</form>
");
} else if (!$SecondField) {
$error_field="SecondField";
die("
<form method=post>\n
You didnt enter a value into the SecondField field.\n
<input type=hidden name=error_field value=$error_field>\n
<input type=submit value=OK>\n
</form>
");
}
?>
Thanks in advance.