View Full Version : Form Field Highlight
kathryn
01-28-2003, 10:22 AM
Hi,
When a user submits my form and hasn't entered a value in a mandatory field I want to get the form returned to them with that fields description highlighted in red???
Can i do this with javascript???
and a message in red at the top of the form telling them they need to fill in fields marked in red???
any ideas, thanks
Kathryn
Danne
01-28-2003, 12:59 PM
Try something like this:
<html>
<head>
<title> Título </title>
</head>
<script language="javascript">
function validate(value)
{
return (value=="");
}
function checkfields(form)
{
var i,isValid=true;
for(i=0;i<form.elements.length;i++)
if(validate(form.elements[i].value))
{
form.elements[i].style.border="2px solid #FF0000";
isValid=false;
}
return isValid;
}
</script>
<body onload="">
<form method=post action="" onSubmit="return(checkfields(this));">
<table border=0 cellspacing=5 cellpadding=0>
<tr>
<td>
field1<br>
<input type="text" name="field1"></td>
<td>
field2<br>
<input type="text" name="field2"></td>
</tr>
<tr>
<td>
field3<br>
<input type="text" name="field3"></td>
<td>
field4<br>
<input type="text" name="field4"></td>
</tr>
</table>
<input type="submit">
</form>
</body>
</html>
I don't have to do anything for NS, but from what I read in the documentation, it should work there too...:D
kathryn
01-28-2003, 01:11 PM
Thanks for that,
Kathryn
whammy
01-29-2003, 12:48 AM
Just out of curiosity, what happens when you submit the form? Are you submitting it to a remote server, or do you have the ability to modify the server-side processing?
I only ask because this kind of thing is more reliable server-side (and generally easier) if you have the capability. The knowledge can be learned. ;)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.