While it is possible to have fields on the same page interact with each other using JavaScript, I don't think this is necessary for the behavior you are after.
Instead of fields in a free format question, you could add these two variables as pass-in fields to your questionnaire. Then, on the page where you want to run the calculations and display the category, place code like this:
[% Begin Unverified Perl
my $sum = GETVALUE('Q1_1') + GETVALUE('Q1_2') + GETVALUE('Q1_3');
SETVALUE('pif1', $sum);
my $category;
if ($sum <= 20) {
$category = 1;
}
elsif ($sum <= 40) {
$category = 2;
}
SETVALUE('pif2', $category);
return $category;
End Unverified %]
"pif1" and "pif2" must be replaced with the names of your two pass-in fields. Line 2 can be updated to reflect the names of the fields you want to sum together. Lines 7 through 12 can be updated and repeated to reflect the rules of your categorization.
Does that suit your needs?