I'm trying to remember and modify values based on radio selections. If radio1 is selected, it should read value1 and value 2's values and save them as the data attribute "previous-value", and then set those values to either 0 or 1. If radio2 is selected, then value1 should be set to 0, and value2 should be set to the previous-value. However that is not happening, the previous-value data doesnt seem to be setting. I don't have any console errors. I'm wondering if setting the values and changing the values with the same action is causing an issue.
$('input[type="radio"]').click(function() {
var $value1 = $('#value1');
var $value2 = $('#value2');
if($(this).attr('id') == 'radio1') {
$value1.data('previousvalue', $value1.val());
$value1.val('1');
$value2.data('previousvalue', $value2.val());
$value2.val('0');
} else if($(this).attr('id') == 'radio2') {
$value1.val('0');
$value2.val($value2.data('previousvalue'));
}
});