SHARE
TWEET

Untitled

a guest Mar 20th, 2017 82 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("loginError").style.display = "none";
  42.  
  43.         document.getElementById("todolist").appendChild(li);
  44.  
  45.         var buffer = document.getElementById("labelName").value;
  46.  
  47.         jQuery.post("http://localhost:3307/todo", {data: JSON.stringify(buffer)}, function(){alert("Data posted successfully!")});
  48.  
  49.     }
  50.     document.getElementById("labelName").value = "";
  51.  
  52.     var span = document.createElement("SPAN");
  53.     var txt = document.createTextNode("\u00D7");
  54.     span.className = "close";
  55.     span.appendChild(txt);
  56.     li.appendChild(span);
  57.  
  58.     for (i = 0; i < close.length; i++) {
  59.         close[i].onclick = function() {
  60.             var div = this.parentElement;
  61.             div.style.display = "none";
  62.         }
  63.     }
  64. }
  65.  
  66. function saveList() {
  67.     var list = document.getElementsByClassName("todoLi");
  68.  
  69.  
  70. }
  71.  
  72. $("#logInButton").click(function() {
  73.  
  74.     var username = document.getElementById("username").value;
  75.     var password = document.getElementById("password").value;
  76.  
  77.     if (username == "admin" && password == "admin" && $('#logInCheckBox').is(':checked')) {
  78.         localStorage.setItem("username", username);
  79.         localStorage.setItem("password", password);
  80.  
  81.         return true;
  82.     } else if (username == "admin" && password == "admin") {
  83.         return true;
  84.     } else {
  85.         document.getElementById("loginError").innerHTML="Missing or incorrect user info. Please try again!";
  86.         document.getElementById("loginError").style.display = "inline-block";
  87.  
  88.         return false;
  89.     }
  90.  
  91.     var username = document.getElementById("username").value = "";
  92.     var password = document.getElementById("password").value = "";
  93. });
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