While loop within Javascript function

Posted by JM4 on Stack Overflow See other posts from Stack Overflow or by JM4
Published on 2010-05-26T22:25:22Z Indexed on 2010/05/26 22:31 UTC
Read the original article Hit count: 266

Filed under:
|

I have the following basic function:

<script type="text/javascript">
function Form_Data(theForm)
{

var t=1;
while (t<=5) {

if (theForm.F[t]FirstName.value == "")
    {
    alert("Please enter Fighter 1's First Name.");
    theForm.F[t]FirstName.focus();
    return (false);
    }
t++;
}

return (true);
}
</script>

The script (js validation) fails using this code. If I remove the [t] and replace with a number (1,2,3,4,etc), the validation works on the appropriate fields. What am I doing wrong?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about validation