2

I'm trying to write a simple for loop and I keep getting this error:

missing ; after for loop initializer.

I can't seem to figure out why. cleari is an array of input fields. So, I'm basically trying to take each field in the array, and reset it:

var cleari = document.getElementById(rowNum).getElementsByTagName('input');
for (cleari) {
    cleari.parentNode.innerHTML = cleari.parentNode.innerHTML;
}
0

2 Answers 2

3

I think you might have been looking for the for...in loop:

var clearis = document.getElementById(rowNum).getElementsByTagName('input');

for(cleari in clearis)
{
    clearis[cleari].parentNode.innerHTML = clearis[cleari].parentNode.innerHTML;
}

You can read more about the for...in loop at the Mozilla Developer Network

Sign up to request clarification or add additional context in comments.

1 Comment

It worked! I dont exactly understand it! But thats ok, ill figure it out later. thanks.
1

A for loop is of the convention for(a;b;c)

For example:

for(var i = 0; i < 10; ++i)  {
     alert(i);
} 

A while loop is of the convention while(a)

For example:

var i = 0;
while(i < 10){
    alert(i);
    ++i;
}

So for your example what you can do is:

for(var i = 0; i < cleari.length; i++){
    cleari[i].parentNode.innerHTML = cleari[i].parentNode.innerHTML;
}

1 Comment

See also for..of and for..in

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.