Code description:
Clicking the button (id=a1) will add text input brackets (e.g. 3 clicks will give 3 text input). I am trying to get the values from all the text inputs and show it on the page,however, my code only prints out the value from the first text input. How can I get it to print all the values from all the text inputs?
// add textbox function onclick
var a1 = 0;
var x = [];
function addInput() {
document.getElementById('text').innerHTML += "Load magnitude <input type='text' id='a1' value=''/><br />";
a1 += 1;
}
//Adds inout into list var x
function pushData()
{
//get value from input text
var inputText = document.getElementById('a1').value;
//append data to the array
x.push(inputText);
var pval = x;
document.getElementById('pText').innerHTML = pval;
}
<!--Loadtype selection-->
<div class="test">
Load type:<br>
<img src="https://upload.wikimedia.org/wikipedia/commons/a/a0/Circle_-_black_simple.svg" width="50 height=" 50 alt="unfinished bingo card" onclick="addInput()" />
<br><br>
</div>
<p id="text"></p>
<button onclick="pushData();">Submit</button>
<p id="pText">List from input inserted here!</p>
<p id="pText2">value of a1</p>