0
<input id="in1" value="1">
<input id="in2" value="5">

var text = "";
var t = document.querySelector("#in1").value;
var s = document.querySelector("#in2").value;
for (; t < s+1; t++) {
    text += "List " + t + "<br>";
}

I got one problem and 1 question. The problem : when using +1 for the loop , the list generated is 1 to 50 instead of 1 to 5.

The question. How to add 0 in front of 1 to 9 if <input id="in2" value="11">

Result:

List 01
List 02
List 03
List 04
List 05
List 06
List 07
List 08
List 09
List 10
List 11
hannaTY5
  • 13
  • 1
  • 1
    As for your `+1` question, `.value` returns the number as a string, so `s+1` works as string concatenation `'5'+1` = `'51'`. Use `parseInt()` to convert value to a number. – DarthJDG Aug 15 '17 at 10:12
  • @adeneo I don't think this is a duplicate of that ? – Suresh Atta Aug 15 '17 at 10:16
  • he is talking about "The question. How to add 0 in front of 1 to 9",was able to get it to work. Thanks for answer – hannaTY5 Aug 15 '17 at 10:40

1 Answers1

1

That is because s is a String. So s+1 is 51 instead of 6. You have to convert that to integer.

for (; t < parseInt(s)+1; t++) {
Suresh Atta
  • 120,458
  • 37
  • 198
  • 307