Skip to content

Instantly share code, notes, and snippets.

@ngocminhxx

ngocminhxx/main.js

Last active Sep 16, 2020
Embed
What would you like to do?
jQuery(function ($) {
var $agreeCheckbox = $("input[name='agree-checkbox");
var $btnModal = $("#btn-modal");
var $modalTrigger = $('.modal-trigger');
//GET ITEM FIRST
var checkData = localStorage.getItem("checkData");
if (checkData == "yes") { // if "YES" do....
$agreeCheckbox.prop('checked', true);
}
else if(checkData == "no"){
$agreeCheckbox.prop('checked', false); // if "NO" do....
}
$btnModal.attr('disabled',true);
if ($agreeCheckbox.is(":checked")) {
$btnModal.attr('disabled',false);
$modalTrigger.removeAttr("data-toggle");
} else {
$btnModal.attr('disabled',true);
$modalTrigger.attr("data-toggle", "modal");
}
$agreeCheckbox.on('click', function (event) {
if ($(this).prop("checked")) {
$btnModal.attr('disabled',false);
$modalTrigger.removeAttr("data-toggle");
localStorage.setItem("checkData", "yes"); // Set "YES" if checkbox is not checked
} else {
$btnModal.attr('disabled',true);
$modalTrigger.attr("data-toggle", "modal");
localStorage.setItem("checkData", "no"); // Set "NO" if checkbox is not checked
}
});
$btnModal.on('click', function (event) {
if ($btnModal.attr('disabled',false)) {
document.location.href = "./form.php";
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.