user3218321
user3218321

Reputation: 13

Problems with loops and integers in javascript

I've been teaching myself javascript for the past week or so and I've been stuck for the past couple days on loops.

I have a list of 15 items on a page, 15 text boxes to exact and I wish to copy them from one side of the screen to the other with a loop and 15 tags.

var variablenamer = "reitem"; 
var number = i; 
var stringholder = variablenamer.concat(number);
document.getElementById(stringholder).innerHTML = "test"

This code works outside of a loop,(provided I set i to 1).

so I try to make it a loop like so:

for (i = 1, i < 16, i++){
    var variablenamer = "reitem";
    var number = i;
    var stringholder = variablenamer.concat(number);
    document.getElementById(stringholder).innerHTML = "test";
}

and all of the code on my page stops working. What am I doing wrong? Thanks for your help.

-Fred

Upvotes: 0

Views: 61

Answers (2)

saman khademi
saman khademi

Reputation: 842

var i;
for (i=1;i<16;i++){
    var variablenamer = "reitem";
    var number = i;
    var stringholder = variablenamer.concat(number);
    document.getElementById(stringholder).innerHTML = "test";
}

Upvotes: 0

Sarath
Sarath

Reputation: 9146

its semicolon

for (var i=1 ; i<16 ; i++){

}

Upvotes: 5

Related Questions