Hi here is two input field with type=“number” and I am also inserting numbers too but the results is concatenating of two fields data instead of adding? I am New to JS. Can you help me why this is happening?
<input type="number" placeholder="Type number1" id="number1">
<input type="number" placeholder="Type number2..." id="number2">
<button type="button" onclick="getInputValue();">Get Value</button>
<script>
function getInputValue(){
// Selecting the input element and get its value
var inputVal2 = document.getElementById("number1").value;
var inputVal3 = document.getElementById("number2").value;
var sum = inputVal2 + inputVal3;
// Displaying the value
alert(sum);
}
</script>