I have two HTML input elements. I need to get an output by add those input values together. I created a JavaScript function to do that but, the output is "NaN" always.
HTML:
<input type="text" id="value1" /> <br/>
<input type="text" id="value2" /> <br/>
<button id="button1" onclick="calc()">Calculate</button>
<p id="result"></p>
JavaScript:
function calc()
{
var x1 = document.getElementById('value1');
var x2 = document.getElementById('value2');
var r = x1+x2;
document.getElementById('result').innerHTML=r;
}
How do I get the real output here?