I am trying to have the NumberBox's onEnter() function to be able to dynamically change the formBox.
If someone types 3 as the input value, I need it to show 3 forms with the exact input boxes. I know how to get the value from the input box and show the amount of forms below.
My problem is that I cannot figure out how to have one submit button store all of the values into an array, such as [[1,1,1,1,1],[2,2,2,2,2],etc].
Once I can figure this out, I should be able to output those values on my own. End goal is to use those values to show the list multiple times on another page. I would prefer to keep this completely in Javascript. I believe it can be done, but I have hit a block and need some help.
function clickMe() {
var input1 = document.forms["formBox"]["info1"].value;
var input2 = document.forms["formBox"]["info2"].value;
var input3 = document.forms["formBox"]["info3"].value;
var input4 = document.forms["formBox"]["info4"].value;
var input5 = document.forms["formBox"]["info5"].value;
var inputArr = [input1,input2,input3,input4,input5];
document.getElementById("info1").innerHTML = inputArr[0];
document.getElementById("info2").innerHTML = inputArr[1];
document.getElementById("info3").innerHTML = inputArr[2];
document.getElementById("info4").innerHTML = inputArr[3];
document.getElementById("info5").innerHTML = inputArr[4];
console.log(inputArr);
}
function onEnter() {
var qNumber = document.getElementsByName("numberBox")[0].value;
if(event.keyCode == 13) {
var qID = document.getElementById("numBox");
var submitBtn = document.getElementById("submitButton");
var a = qNumber - 1;
var b = 0;
while (b < a) {
var formClone = document.getElementById("formBox");
var listClone = formClone.cloneNode(true);
var text =b+2;
listClone.id = "formBox" + text;
console.log(listClone.id);
document.getElementById("forms").append(listClone);
b++;
console.log(b);
}
return qID.parentNode.removeChild(qID);
}
return qNumber;
}
input{
display: block;
}
<div id="forms">
<span id="numBox">
<label for="numberBox">Number of Forms</label>
<input type="number" name="numberBox" onkeydown="onEnter()" />
</span>
<form id="formBox" name="formBox" action="#" onsubmit="return false;">
<label for="info1">Input 1:</label>
<input type="text" name="info1" />
<label for="info2">Input 2:
</label>
<input type="text" name="info2" />
<label for="info3">Input 3:
</label>
<input type="text" name="info3" />
<label for="info4">Input 4:
</label>
<input type="text" name="info4" />
<label for="info5">Input 5:
</label>
<input type="text" name="info5" />
</form>
</div>
<input type="submit" value="Submit" id="submitButton" onclick="clickMe()" />
<div id="content">
<span id="info1">input1</span>
<br/>
<span id="info2">input2</span>
<br/>
<span id="info3">input3</span>
<br/>
<span id="info4">input4</span>
<br/>
<span id="info5">input5</span>
</div>