Manariba
Manariba

Reputation: 376

Give i+1 in for loop javascript

I have a for loop in Javascript. How can I give the i+1 (last statement in for loop)? If I'm doing just i+i, the output is wrong.

for (var i=0; i<aantal; i++)
{
    strOutput += "<p><form action='' method='POST'>";
    strOutput += "<input class= 'nummers' type='number' name='aantal' min='1' max='20'>";
    strOutput += "<input type='submit' value='In mandje' name= 'toevoegen'>";
    strOutput += "<input type='hidden' name='id' value='" + i +"'>";
}

Upvotes: 0

Views: 249

Answers (2)

Burak Karakuş
Burak Karakuş

Reputation: 1410

You can do it like this:

strOutput += "<input type='hidden' name='id' value='" + (i+1) +"'>";

Upvotes: 1

axelduch
axelduch

Reputation: 10849

You could increment your boundaries, since you don't use i for something else in this loop

for (var i = 1; i <= aantal; i++)

Upvotes: 4

Related Questions