When you write JavaScript, it's important to tell the code when it should run. You'll usually want to put all of your code within a $(document).ready function, as shown in the code below. This ensures that your code will run after the page loads. Then, using the .blur() method, you can have a function run when the user leaves a field (I like this for calculations).
$(document).ready(function () {
$('#q1 input, #q2 input').blur(function () {
$('#q3 input').val($('#q1 input').val() - $('#q2 input').val());
});
});
So, this code loads when the page is finished loading, and when the user leaves field 1 or field 2, the subtracted total is updated and placed in the field 3.