<html>
<body>
<input type="text" id="array[]" oninput="myFunction(this.value)">
<input type="text" id="array[]" oninput="myFunction(this.value)">
<p id="result"></p>
<script>
function myFunction(val) {
document.getElementById("result").innerHTML = val;
}
</script>
</body>
</html>
I want to add up the two array and show it in "result". But currently it will just show one. Can i know how to add the two array in javascript? For example: user input 1 + input 2, it will show 3 in bottom.
Add a class attribute in the input element or use the tag selector in
querySelectorAll
. then loop over the input element and sum the values.