Reputation: 376
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
Reputation: 1410
You can do it like this:
strOutput += "<input type='hidden' name='id' value='" + (i+1) +"'>";
Upvotes: 1
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