Something I seem to need a lot.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
function calculate(form, id) { a = form.q1.value; b = form.q2.value; switch(id) { case 1: total = (a / 100) * b; //What is a percent of b? break; case 2: total = (a / b) * 100; //a is what percent of b? break; case 3: total = (b - a) / a * 100; //What is the percentage increase/decrease from a to b? break; case 4: total = (a / b) * 100; //a is b percent of what? break; } form.total.value = total; } |