Facebook
From asgagaga, 3 Weeks ago, written in JavaScript.
Embed
Download Paste or View Raw
Hits: 138
  1. var password = document.getElementById("password")
  2.   , confirm_password = document.getElementById("confirmPassword");
  3.  
  4. document.getElementById('signupLogo').src = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSJZhNXJlPcwySsmDH7SnjadPo9eN5gDnsG0tqeL4vvUw&s";
  5. enableSubmitButton();
  6.  
  7. function validatePassword() {
  8.   if(password.value != confirm_password.value) {
  9.     confirm_password.setCustomValidity("Passwords Don't Match");
  10.     return false;
  11.   } else {
  12.     confirm_password.setCustomValidity('');
  13.     return true;
  14.   }
  15. }
  16.  
  17. password.onchange = validatePassword;
  18. confirm_password.onkeyup = validatePassword;
  19.  
  20. function enableSubmitButton() {
  21.   document.getElementById('submitButton').disabled = false;
  22.   document.getElementById('loader').style.display = 'none';
  23. }
  24.  
  25. function disableSubmitButton() {
  26.   document.getElementById('submitButton').disabled = true;
  27.   document.getElementById('loader').style.display = 'unset';
  28. }
  29.  
  30. function validateSignupForm() {
  31.   var form = document.getElementById('signupForm');
  32.  
  33.   for(var i=0; i < form.elements.length; i++){
  34.       if(form.elements[i].value === '' && form.elements[i].hasAttribute('required')){
  35.         console.log('There are some required fields!');
  36.         return false;
  37.       }
  38.     }
  39.  
  40.   if (!validatePassword()) {
  41.     return false;
  42.   }
  43.  
  44.   onSignup();
  45. }
  46.  
  47. function onSignup() {
  48.   var xhttp = new XMLHttpRequest();
  49.    xhttp. {
  50.    
  51.     disableSubmitButton();
  52.    
  53.     if (this.readyState == 4 && this.status == 200) {
  54.       enableSubmitButton();
  55.     }
  56.     else {
  57.       console.log('AJAX call failed!');
  58.       setTimeout(function(){
  59.         enableSubmitButton();
  60.       }, 1000);
  61.     }
  62.    
  63.   };
  64.  
  65.   xhttp.open("GET", "ajax_info.txt", true);
  66.   xhttp.send();
  67. }