SHARE
TWEET

Untitled

a guest Mar 20th, 2017 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Create a "close" button and append it to each list item
  2. var myNodelist;
  3. myNodelist = document.getElementsByClassName("todoLi");
  4. var i;
  5. for (i = 0; i < myNodelist.length; i++) {
  6.     var span = document.createElement("SPAN");
  7.     var txt = document.createTextNode("\u00D7");
  8.     span.className = "close";
  9.     span.appendChild(txt);
  10.     myNodelist[i].appendChild(span);
  11. }
  12.  
  13. // Click on a close button to hide the current list item
  14. var close = document.getElementsByClassName("close");
  15. var i;
  16. for (i = 0; i < close.length; i++) {
  17.     close[i].onclick = function() {
  18.         var div = this.parentElement;
  19.         div.style.display = "none";
  20.     }
  21. }
  22.  
  23. // Add a "checked" symbol when clicking on a list item
  24. var list = document.querySelector('ul');
  25. list.addEventListener('click', function(ev) {
  26.     if (ev.target.tagName === 'LI') {
  27.         ev.target.classList.toggle('checked');
  28.     }
  29. }, false);
  30.  
  31. // Create a new list item when clicking on the "Add" button
  32. function newElement() {
  33.     var li = document.createElement("li");
  34.     var inputValue = document.getElementById("labelName").value;
  35.     var t = document.createTextNode(inputValue);
  36.     li.appendChild(t);
  37.     if (inputValue === "") {
  38.         document.getElementById("loginError").innerHTML="Missing label. Please try again!";
  39.         document.getElementById("loginError").style.display = "inline-block";
  40.     } else {
  41.         document.getElementById("todolist").appendChild(li);
  42.  
  43.         jQuery.post("http://localhost:3307/todo", document.getElementById("labelName").value, function(){alert("Data posted successfully!")}, "text");
  44.  
  45.     }
  46.     document.getElementById("labelName").value = "";
  47.  
  48.     var span = document.createElement("SPAN");
  49.     var txt = document.createTextNode("\u00D7");
  50.     span.className = "close";
  51.     span.appendChild(txt);
  52.     li.appendChild(span);
  53.  
  54.     for (i = 0; i < close.length; i++) {
  55.         close[i].onclick = function() {
  56.             var div = this.parentElement;
  57.             div.style.display = "none";
  58.         }
  59.     }
  60. }
  61.  
  62. function saveList() {
  63.     var list = document.getElementsByClassName("todoLi");
  64.  
  65.  
  66. }
  67.  
  68. $("#logInButton").click(function() {
  69.  
  70.     var username = document.getElementById("username").value;
  71.     var password = document.getElementById("password").value;
  72.  
  73.     if (username == "admin" && password == "admin" && $('#logInCheckBox').is(':checked')) {
  74.         localStorage.setItem("username", username);
  75.         localStorage.setItem("password", password);
  76.  
  77.         return true;
  78.     } else if (username == "admin" && password == "admin") {
  79.         return true;
  80.     } else {
  81.         document.getElementById("loginError").innerHTML="Missing or incorrect user info. Please try again!";
  82.         document.getElementById("loginError").style.display = "inline-block";
  83.  
  84.         return false;
  85.     }
  86.  
  87.     var username = document.getElementById("username").value = "";
  88.     var password = document.getElementById("password").value = "";
  89. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top