SHARE
TWEET

Untitled

a guest Jan 24th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. document.getElementById('btnTrigger').addEventListener('click',function(){
  2.     addDataToTable();
  3.    });
  4.  
  5.   document.getElementById('deleteAllRows').addEventListener('click',function(){
  6.     deleteAllRows();
  7.   });
  8.  
  9.  
  10.     function addDataToTable() {
  11.     askData();
  12.     createRow();
  13.     fillRow();
  14.   }
  15.  
  16.   function askData() {
  17.     var returnToAsk = true;
  18.     while (returnToAsk) {
  19.       window.name = prompt('Enter Your Name');
  20.       returnToAsk = validateName();
  21.     }
  22.     returnToAsk = true;
  23.     while (returnToAsk) {
  24.       window.surname = prompt('Enter your surname');
  25.       returnToAsk = validateSurname();
  26.     }
  27.     returnToAsk = true;
  28.     while (returnToAsk) {
  29.       window.phonenumber = prompt('Enter your phone nubmer');
  30.       returnToAsk = validatePhoneNumber();
  31.     }
  32.   }
  33.  
  34.   function createRow() {
  35.     window.nameTableRow = document.createElement('td');
  36.     window.nameTableRow.className = "nameData";
  37.     window.surnameTableRow = document.createElement('td');
  38.     window.surnameTableRow.className = "surnameData";
  39.     window.phonenumber1 = document.createElement('td');
  40.     window.phonenumber1.className = "numberData";
  41.     window.button = document.createElement('button');
  42.     window.dataRow = document.createElement('tr');
  43.     window.dataRow.className = "tableRow";
  44.     dataRow.appendChild(window.nameTableRow);
  45.     dataRow.appendChild(window.surnameTableRow);
  46.     dataRow.appendChild(window.phonenumber1);
  47.     window.button.classList.add('removeBtn');
  48.  
  49.      window.button.addEventListener('click',function(){
  50.      deleteYourRow(this);
  51.    })
  52.     dataRow.appendChild(window.button);
  53.     window.button.innerHTML = "remove";
  54.     window.body = document.getElementById("body");
  55.     body.appendChild(dataRow);
  56.   }
  57.  
  58.   function fillRow() {
  59.     var saveName =  window.dataRow.getElementsByClassName("nameData")[0];
  60.     saveName.innerHTML = window.name;
  61.     var saveSurname = window.dataRow.getElementsByClassName("surnameData")[0];
  62.     saveSurname.innerHTML = window.surname;
  63.     var saveNumber = window.dataRow.getElementsByClassName("numberData")[0];
  64.     saveNumber.innerHTML = window.phonenumber;
  65.   }
  66.  
  67.   function deleteAllRows() {
  68.     document
  69.       .querySelectorAll('.tableRow')
  70.       .forEach(item => item.remove());
  71.   }
  72.  
  73.   function deleteYourRow(self) {
  74.      self.parentNode.remove();
  75.   }
  76.   function validateName(){
  77.     var buffer = window.name.search( /[^a-z]/i );
  78.     if (buffer < 0 && window.name.length < 32){
  79.       return false;
  80.     }
  81.     alert("name xuina");
  82.     return true;
  83.   }
  84.   function validateSurame(){
  85.     var buffer = window.surname.search( /[^a-z]/i );
  86.     if (buffer < 0 && window.surname.length < 32){
  87.       return false;
  88.     }
  89.     alert("surname xuina");
  90.     return true;
  91.   }
  92.   function validatePhoneNumber(){
  93.     var buffer = window.phonenumber.search( /[^\d]/i );
  94.     if (buffer < 0 && window.phonenumber.length < 32){
  95.       return false;
  96.     }
  97.     alert("phonenumber xuina");
  98.     return true;
  99.   }
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