-1

How could I get the Final Total based on the sum of a checkbox value and the contents of a textbox?

JSFiddle example

My HTML:

<table border="1">
<tr><td>10<input type="checkbox" class="tot_amount" value="10"></td><td>10<input id="os1" type="text"></td></tr>
<tr><td>20<input type="checkbox" class="tot_amount" value="20"></td><td>20<input id="os2" type="text" ></td></tr>
<tr><td>Total<input type="text" id="total1" readonly></td><td>Total2<input id="total2" type="text" readonly></td></tr>
</table>
Final Total<input type="text" id="final" readonly >

And Javascript:

$(".tot_amount").click(function(event) {
var total = 0;
$(".tot_amount:checked").each(function() {
total += parseInt($(this).val());
});

if (total == 0) {
$('#total1').val('');
}
else {
$('#total1').val(total);
}
});



$('#os1, #os2').on('input',function(){
var os1= parseFloat($('#os1').val()) || 0;
var os2= parseFloat($('#os2').val()) || 0;

$('#total2').val(os1 + os2); 

});
2

1 Answer 1

0

Just bind a focus event and do it -

$('#final').bind('focus',function(){
    $(this).val(parseInt($('#total1').val())+parseInt($('#total2').val())); 
                         });

LIVE http://jsfiddle.net/mailmerohit5/h43te3z6/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.