how can i take an input with a textbox1 // use a for loop to count till 50 // and output it in textbox2

Multi tool use


how can i take an input with a textbox1 // use a for loop to count till 50 // and output it in textbox2
i got a textbox id="t1" that takes one input
lets say the input is: 20
i use a nother textbox id="t2" for the output which shoold look like this:
21
22
23
24
25
...
49
50
1
2
3
4
5
...
max lenght of the "numbers" = 50 with a break after every number
i did the following code::
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript">
function add()
{
var a = document.getElementById("t1").value;
for(i = a; i<51; i++) {
a+=i +"<br>";
}
document.getElementsByName("t4")[0].value= a;
}
</script>
</head>
<body>
<input class="t1" type="number" id="t1">
<button onclick="add()">Add</button>
<br><br>
<input style="height: 500px;" class="t2" type="textbox" name="t4"></input>
</body>
</html>
which rly don't work like I want, what am I doing wrong here?
2 Answers
2
Try to change the second textbox to 'textarea' and use 'n' instead of <br/ >
<br/ >
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript">
function add()
{
var a = document.getElementById("t1").value;
for(i = a; i<51; i++) {
a += i + "n";
}
document.getElementsByName("t4")[0].value = a;
}
</script>
</head>
<body>
<input class="t1" type="number" id="t1">
<button onclick="add()">Add</button>
<br><br>
<textarea style="height: 500px;" class="t2" type="textbox" name="t4"></textarea>
</body>
</html>
There is no <input type="textbox">
, use <textarea>
tag for multyline textbox.
If you need 50 numbers, you have to iterate 50 times.
And you need some logic to start over when number reaches 50.
<input type="textbox">
<textarea>
Run the snippet below:
function add() {
var a = [+document.getElementById("t1").value + 1];
for (var i = 0; i < 49; i++) a.push(a[i] + 1 - 50 * ((a[i] || 0) > 49));
document.getElementsByName("t4")[0].value = a.join('n');
}
<input class="t1" type="number" id="t1" value="10">
<button onclick="add()">Add</button>
<br><br>
<textarea style="height: 200px;" class="t2" name="t4"></textarea>
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.