I am wondering what the best practice is for calulating form sections into a form total. E.g., the top of the form has some radio buttons with price values, when a value is selected the total field at the bottom of the form is updated. There is also a set of checkboxes with values, with a click event, clicking any of these will update the value of the total input field.
The problem I run into is calculating vars when they are inside different functions. How does one go about doing this? Here is what I have: //Find if user is attending $('#attendingOptions input').change(function() { if ($('#q38480_q1_0:checked').length === 1) { var attendVal = 175; $('#q38487_q1').val('175'); } else { var attendVal = 0; $('#q38487_q1').val('0'); } }); //Calculate awards lunch value var lunchVal = parseInt($('#q38481_q3').val()) * 50; $('#sponsorOptions :checkbox').click( function() { var valueStart = 0; $('#sponsorOptions input:checkbox:checked').each(function() { valueStart += parseInt($(this).val()); }); $('#q38487_q1').val(valueStart + attendVal); }) Right now the calculation does not work because attendVal is inside another function.