I've searched a couple forums and been googling all over the web but I can't find out what I'm doing wrong here. I have a huge form and I'm trying to make sure the textboxes aren't blank. If they are I'm placing a red arrow by the respective box.
I've cut the code down to the following, alerting the name of the field rather than putting in a red arrow (already have that part working). The document.test.FieldName[i].value=="" is causing problems I assume. I wanted to loop through an array rather than have an IF statement for each textbox because I have 40 textboxes.
HTML Code:
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
<!--
function validate(){
var FieldName=new Array(2);
FieldName[0]="text1";
FieldName[1]="text2";
var i=0
for (i=0; i<2; i++){
if ( document.test.FieldName[i].value=="" ){
alert('This isnt filled in: ' + FieldName[i]);
}
}
return true;
}
// -->
</SCRIPT>
</head>
<body>
<form name="test">
<input type="text" name="text1">
<input type="text" name="text2">
</form>
<a href="#" onclick="validate()">Click Me</a>
</body>
</html>
|