my expected output is
As i type on input text field i get instant sum on third text field
if i type 3 on first text field and key is up , instantly 3+0=3 have to show on third field
but doesnt show any result
$(document).ready(function(){
var a=0, b=0,c=0;
$("input:#a").keyup(function(){
a=$("input:#a").val();
c=a+b;
$("input:#c").append(a+"+"+"b"+"="+c);
});
$("input:#a").keyup(function(){
b=$("input:#b").val();
c=a+b;
$("input:#c").append(a+"+"+b+"="+c);
});
});
<tr><td><input type="text" id="a"></td></tr>
<tr><td><input type="text" id="b"></td></tr>
<tr><td><input type="text" id="c"></td></tr>
You need something along the lines of the following:
<table>
<tbody>
<tr><td>A<input type="text" id="a" /></td></tr>
<tr><td>B<input type="text" id="b" /></td></tr>
<tr><td>C<input type="text" id="c" /></td></tr>
</tbody>
</table>
<!-- If you need this: -->
<script src="http://code.jquery.com/jquery-1.9.0.min.js"></script>
$(document).ready(function(){
var a=0,
b=0;
$('input#a').bind('keyup', function(e){
a = parseInt($(this).val()) || 0;
var c = (a + b);
$('input#c').val(a + '+' + b + '=' + c);
});
$('input#b').bind('keyup', function(e){
b = parseInt($(this).val()) || 0;
var c = (a + b);
$('input#c').val(a + '+' + b + '=' + c);
});
});
This code performs the calculation and puts the result in box C, and automatically updates C with the result of the calculation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With