Guest User

Untitled

a guest
Dec 16th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. const chkBox = document.querySelectorAll("input[type=checkbox]");
  2.  
  3. for (box of chkBox) {
  4. box.addEventListener("change", updateUser, false);
  5. }
  6.  
  7. function updateUser() {
  8.  
  9. const messageBox = document.getElementById("message");
  10.  
  11. if (this.checked) {
  12.  
  13. // Getting the values to post to the server and the initialization requirements
  14. const postingValues = JSON.stringify({id:this.value, validated:true});
  15. const fetchInit = {method: "POST", headers: {"Content-type": "application/json"}, body: postingValues};
  16.  
  17. // Making the fetch call and returning the message to the user
  18. fetch("index.php?action=updateLogin", fetchInit).then(function(response) {
  19. response.text().then(function(value) {
  20. messageBox.innerHTML = value;
  21. });
  22. });
  23. } else {
  24.  
  25. // Getting the values to post to the server and the initialization requirements
  26. const postingValues = JSON.stringify({id:this.value, validated:false});
  27. const fetchInit = {method: "POST", headers: {"Content-type": "application/json"}, body: postingValues};
  28.  
  29. // Making the fetch call and returning the message to the user
  30. fetch("index.php?action=updateLogin", fetchInit).then(function(response) {
  31. response.text().then(function(value) {
  32. messageBox.innerHTML = value;
  33. });
  34. });
  35. }
  36. }
Add Comment
Please, Sign In to add comment