document.addEventListener('DOMContentLoaded', function() { M.AutoInit(); var elems = document.querySelectorAll('.modal'); var instances = M.Modal.init(elems, {dismissible:false}); }); function sendData(page,postdata){ var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { return this.responseText; } }; xhttp.open("POST", page+".php", true); xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xhttp.send(postdata); } function checkLogin(){ sendData("islogin",""); } function validateLogin(){ var toValidate = { email: "Email is Required", company: "Company is Required", password: "Password is Required", }; var idKeys = Object.keys(toValidate); var allValid = true; idKeys.forEach(function(id){ var isValid = checkIfValid(id, toValidate[id]); if(!isValid){ allValid = false; } }); if (allValid){ login(); return false; } } function checkIfValid(eId,message){ var isValid = document.getElementById(eId).checkValidity(); if (!isValid) { M.toast({html: message}) return false; } else { return true; } } function login() { var formData = {}; formData.email = document.getElementById("email").value; formData.company = document.getElementById("company").value; formData.password = document.getElementById("password").value; var postdata = "email="+formData.email+"&company="+formData.company+"&password="+formData.password var page = "sql-resp"; var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { document.getElementById("demo").innerHTML = this.responseText; } }; xhttp.open("POST", page+".php", true); xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xhttp.send(postdata); var elem = document.getElementById("modal1"); var instance = M.Modal.getInstance(elem); instance.close(); }