So here's the problem. I have two check boxes, and two text boxes, and one final text box at the bottom. What I'm trying to do is this: When check box 1 is checked, the text box right next to it gets a value of 8. When check box 2 is checked, the text box right next to it gets a value of 7. Then finally the final text box shows the sum of the text boxes, which in this case should be 15.
I've tried this: just give the text boxes values with if statements. Then give a class "textboxes" for both text boxes, and just count the sum of them. I'm able to get the values with if statements, but can't get the final sum of those.
$(function(){
$('#checkbox1').click(function(){
if (this.checked) {
$('#textbox1').val(7);
}
});
$('#checkbox2').click(function(){
if (this.checked) {
$('#textbox2').val(8);
}
});
var total = 0;
$('.textboxes').each(function() {
total += Number($(this).val());
});
$('#totalSum').val(total);
});