I am trying to add two numbers whenever a keyup happens in the textboxes of those two numbers. I want it to use jquery so my addition code is these:
HTML:
<div class="container">
<h1>jQuery live Try</h1>
<form>
<input type="text" placeholder="Number 1" class="num1 key">
<input type="text" placeholder="Number 2" class="num2 key">
<br><br>
Sum: <input type="text" class="sum" readonly="readonly"><br><br><br>
</form>
</div>
Jquery:
$(document).ready(function(){
$(".sum").val("0");
$(".key").val("");
function calc(){
var $num1=$(".num1").val();
var $num2=$(".num2").val();
$(".sum").val($num1+$num2);
}
$(".key").keyup(function(){
calc();
});
});
But if i enter 1 and 2 it outputs 12 not 3. How can I make it output the sum?
$(".sum").val(+$num1+$num2);