I am having trouble grabbing multiple input's using the inputs name and adding multiplications to them like below. Is there another way I can do this without using getElementById ?
<input type="number" name="test1" id="RoundInput1">
<input type="number" name="test2" id="RoundInput2">
<button onclick="GetTheResults()">Try it</button>
<p id="demo">Click the button to change the text in this paragraph.</p>
<script>
x = document.getElementsByName("test1").value;
z = document.getElementsByName("test2").value;
var Savings = x + z;
function GetTheResults() {
document.getElementById("demo").innerHTML = Savings;
}
</script>
Please note I have also tried the following:
x = document.getElementsByName("test1")[0].value;
z = document.getElementsByName("test2")[0].value;
GetTheResults, not actually calling it. To call it, just addGetTheResults()before your</script>tag