Lifeforce
05-31-2003, 03:17 AM
I'm trying to design a script that works for all my forms so I dont have to write a new one for each form. This script works perfectly in IE but but not in Netscrap 7. Could anyone tell me why? I've narrowed it down to the textarea, for some reason the textarea gets by in NN7.
<html>
<head>
<script>
function validate(form)
{
x = form.elements.length
i = 0
while(i < x)
{
if((form.elements[i].value == "" )&&(form.elements[i].alt == "req"))
{
alert("please fill in all required fields")
return false
}
i++
}
}
</script>
</head>
<body>
<form method="post" action="test.php" onSubmit="return validate(this)">
<textarea alt="req"></textarea>
<input alt="req" type="text">
<input alt="req" type="text">
<input type="submit">
</form>
</body>
</html>
<html>
<head>
<script>
function validate(form)
{
x = form.elements.length
i = 0
while(i < x)
{
if((form.elements[i].value == "" )&&(form.elements[i].alt == "req"))
{
alert("please fill in all required fields")
return false
}
i++
}
}
</script>
</head>
<body>
<form method="post" action="test.php" onSubmit="return validate(this)">
<textarea alt="req"></textarea>
<input alt="req" type="text">
<input alt="req" type="text">
<input type="submit">
</form>
</body>
</html>