Click to See Complete Forum and Search --> : a loop gone bad?


rjusa
12-02-2003, 03:32 PM
I have a table 50x1 with the input type=text name="state1"...state50...what I'm trying to do is have the background color change if there is a value in the textbox on submit. I wrote the following:

<script type="text/javascript">
var states=new Array(51);
for (var i=1; i<states.length; i++) {
states[i]="state"+i;
document.write(states[i]);
}
</script>
<script type="text/javascript">
function validate() {
for (var i=1; i<51; i++)
if (document.states1.states[i].value.length > 0)
document.states1.states[i].style.background = '#ffffff';
return false;
}
</script>

<form name="states1">

(I put the write statement in the array builder to make sure the variabvles were being created) Well, the variables do get created but when I execute the 'validate' function I get "document.states1.states is null or not an object" Where'd I goof?

Thanks,
Ron

TheBearMay
12-03-2003, 08:43 AM
Looks like you're trying to reference an array on your form, and the array you've created exists but is not contained in the form. Thus states[i] is valid, but state1.states[i] isn't.