Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lucasstark/919b22ab0c7a751dd8373674749eabb0 to your computer and use it in GitHub Desktop.
Save lucasstark/919b22ab0c7a751dd8373674749eabb0 to your computer and use it in GitHub Desktop.
(function($) {
$(document).ready(function() {
$("input[type=radio]").click(function() {
// Get the storedValue
var previousValue = $(this).data('storedValue');
// if previousValue = true then
// Step 1: toggle radio button check mark.
// Step 2: save data-StoredValue as false to indicate radio button is unchecked.
if (previousValue) {
$(this).prop('checked', !previousValue);
$(this).data('storedValue', !previousValue);
}
// If previousValue is other than true
// Step 1: save data-StoredValue as true to for currently checked radio button.
// Step 2: save data-StoredValue as false for all non-checked radio buttons.
else{
$(this).data('storedValue', true);
$("input[type=radio]:not(:checked)").data("storedValue", false);
}
});
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment