Possible Duplicate:
How to add two strings as if they were numbers?
I wrote a simple JavaScript code and I want to use two input box and add numbers from the two value. Here's the code, and I see the result 1520 instead of 35.
How can I fix it?
n1 <input type = "number" id = "n1" value=15 />
n2 <input type = "number" id = "n2" value=20 />
<p>Sum?</p>
<button onclick="sum()">Try it</button>
<p id="demo2">Result?? </p>
<script type="text/javascript">
function sum()
{
var fn, ln;
fn = document.getElementById("n1").value;
ln = document.getElementById("n2").value;
result = (fn+ln);
document.getElementById("demo2").innerHTML = result;
}
</script>