SHARE
TWEET

Untitled

a guest Jan 22nd, 2020 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <div style="display:flex;justify-content:center">
  2.   <input id="CodeInput" placeholder="Enter Code" style="padding: 15px;
  3.    border-radius: 3px;
  4.    box-shadow: none;
  5.    text-align: center;
  6.    text-transform: uppercase;
  7.    border: 1px solid #ddd;
  8.    font-weight: bolder;"/>
  9.   <button id="CodeSubmit" onclick="onSubmit()" style="padding: 15px;
  10.    border-radius: 100px;
  11.    box-shadow: none;
  12.    border: 0;
  13.    width: 100px;
  14.    background: #622cbe;
  15.    border: 1px solid #ddd;
  16.    color: #fff;
  17.    font-weight: 700;
  18.    margin-left: 15px;">Go</button>
  19. </div>
  20. <div id="ErrorBox" style="display:none;
  21.    border:red;
  22.    text-align:center;
  23.    padding:15px;
  24.    color:red;
  25.    width:258px;
  26.    margin: 0 auto;
  27.    margin-top:15px;
  28.    border: 1px solid red;
  29.    background:transparent"></div>
  30.  
  31. <script>
  32.   let xobj = new XMLHttpRequest();
  33.   let inptCode = document.getElementById("CodeInput")
  34.   let errorBox = document.getElementById("ErrorBox")
  35.  
  36.   let onSubmit = () => {
  37.     let submitCode = document.querySelector("#CodeSubmit")
  38.  
  39.     if (!inptCode.value) {
  40.       alert(`Please enter app code.`)
  41.       return false;
  42.     }
  43.    
  44.     submitCode.style.background='#dddddd';
  45.     submitCode.disabled = true;
  46.     submitCode.innerHTML = "Checking...";
  47.    
  48.     xobj.open('GET', `https://myndapi.sharpenminds.com/v1.20/brand/code?code=${inptCode.value}`);
  49.     xobj.onreadystatechange = function () {
  50.       if (xobj.readyState == 4 && xobj.status == "200") {
  51.        errorBox.style.display = "none";
  52.         submitCode.style.background='#622cbe';
  53.         submitCode.disabled = false;
  54.         submitCode.innerHTML = "Go";
  55.         let res = JSON.parse(xobj.responseText);
  56.         window.open(res.brand_url, '_blank');
  57.       } else {
  58.         let res = JSON.parse(xobj.responseText);
  59.        
  60.         errorBox.style.display = "block";
  61.         errorBox.innerHTML = res.error.message || "Unkown Error";
  62.         submitCode.innerHTML = "Try Again";
  63.         submitCode.disabled = false;
  64.         submitCode.style.background='#622cbe';
  65.        
  66.         setTimeout( () => {
  67.           errorBox.style.display = "none";
  68.         }, 3500)
  69.       }
  70.     };
  71.     xobj.send();
  72.   }
  73.  
  74.   inptCode.addEventListener("keyup", function(event) {
  75.     if (event.keyCode === 13) {
  76.       event.preventDefault();
  77.       onSubmit()
  78.     }
  79.   });
  80. </script>
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