david_j — 2011-06-11T16:21:22-04:00 — #1
Im look for help in building an expenditure calculator
what i am having problems with is I am using radio buttons to multiply form field values
[radio1] = x 1 (week)
[radio2] = x 4 (month)
[radio3] = x 52 (year)
So if you fill out a field and select [radio2] it multiplies the field by 4
If you then select [radio1] it reverts to the original value
Using JQuery what's the best way to do this.
The issue I am having is I need to know the previous selected radio as well as the new one so I know whether to divide or multiply
mickyginger — 2011-06-11T16:30:10-04:00 — #2
var ratio = $(this).val(); //get value of radio button clicked
var fieldVal = $('#formField').val(); //get value of form field
var newVal = ratio * fieldVal; //multiply
$('#formField').val(newVal); //change the form field's value to the result of the multiplication
If you're not using jQuery perhaps it could serve as pseudo-code...? Anyway, I hope that helps.