Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const chkBox = document.querySelectorAll("input[type=checkbox]");
- for (box of chkBox) {
- box.addEventListener("change", updateUser, false);
- }
- function updateUser() {
- const messageBox = document.getElementById("message");
- if (this.checked) {
- // Getting the values to post to the server and the initialization requirements
- const postingValues = JSON.stringify({id:this.value, validated:true});
- const fetchInit = {method: "POST", headers: {"Content-type": "application/json"}, body: postingValues};
- // Making the fetch call and returning the message to the user
- fetch("index.php?action=updateLogin", fetchInit).then(function(response) {
- response.text().then(function(value) {
- messageBox.innerHTML = value;
- });
- });
- } else {
- // Getting the values to post to the server and the initialization requirements
- const postingValues = JSON.stringify({id:this.value, validated:false});
- const fetchInit = {method: "POST", headers: {"Content-type": "application/json"}, body: postingValues};
- // Making the fetch call and returning the message to the user
- fetch("index.php?action=updateLogin", fetchInit).then(function(response) {
- response.text().then(function(value) {
- messageBox.innerHTML = value;
- });
- });
- }
- }
Add Comment
Please, Sign In to add comment