Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.83 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.  
  4. <head>
  5.   <title>Validation</title>
  6.   <style>
  7.     /*buat style tombol silahkan jadi hide /none*/
  8.  
  9.     #tes {
  10.       display: none;
  11.  
  12.     }
  13.  
  14.     .captcha {
  15.       font: italic bold 16px "Comic Sans MS", cursive, sans-serif;
  16.       color: #9e9797;
  17.       background-color: #bbb2b2;
  18.       width: 100px;
  19.       border-radius: 5px;
  20.       text-align: center;
  21.       text-decoration: line-through;
  22.     }
  23.  
  24.     .center {
  25.       position: fixed;
  26.       top: 50%;
  27.       left: 50%;
  28.       transform: translate(-50%, -50%);
  29.       text-align: center
  30.     }
  31.  
  32.     .errmsg {
  33.       color: #ff0000;
  34.     }
  35.   </style>
  36.   <script>
  37.     function pindah(url) {
  38.       window.location = url;
  39.     }
  40.  
  41.     var captcha = new Array();
  42.  
  43.     function validateRecaptcha() {
  44.       var recaptcha = document.getElementById("recaptcha").value;;
  45.       var validRecaptcha = 0;
  46.       for (var z = 0; z < 6; z++) {
  47.        if (recaptcha.charAt(z) != captcha[z]) {
  48.          validRecaptcha++;
  49.        }
  50.      }
  51.      if (recaptcha == "") {
  52.        document.getElementById('errCaptcha').innerHTML = 'Must be Filled';
  53.      } else if (validRecaptcha > 0 || recaptcha.length > 6) {
  54.         document.getElementById('errCaptcha').innerHTML = 'Incorrect';
  55.       } else {
  56.         document.getElementById('errCaptcha').innerHTML = 'Correct';
  57.       }
  58.       // cek validasi caprcha
  59.       if (recaptcha = validRecaptcha) {
  60.         document.getElementById('tes').style.display = 'none';
  61.       } else {
  62.         document.getElementById('tes').style.display = 'block';
  63.       }
  64.     }
  65.     var hidden = false;
  66.  
  67.     function createCaptcha() {
  68.       for (q = 0; q < 6; q++) {
  69.        if (q % 2 == 0) {
  70.          captcha[q] = String.fromCharCode(Math.floor((Math.random() * 26) + 65));
  71.        } else {
  72.          captcha[q] = Math.floor((Math.random() * 10) + 0);
  73.        }
  74.      }
  75.      thecaptcha = captcha.join("");
  76.      document.getElementById('captcha').innerHTML =
  77.        "<span class='captcha'> " + thecaptcha + " </span>" + "&nbsp; <a onclick='createCaptcha()' href='#'>Change Code</a>";
  78.     }
  79.   </script>
  80. </head>
  81.  
  82. <body>
  83.   <div class='center'>
  84.     <table>
  85.       <tr>
  86.         <td>CODE : </td>
  87.         <td id="captcha">
  88.           <script>
  89.             createCaptcha();
  90.           </script>
  91.         </td>
  92.       </tr>
  93.       <tr>
  94.         <td>TYPE :</td>
  95.         <td><input type="text" name="recaptcha" id="recaptcha" placeholder="enter code" /></td>
  96.         <td id="errCaptcha" class="errmsg"></td>
  97.         <td colspan="2" style="text-align:right;">
  98.           <input type="button" value="Submit" onClick="validateRecaptcha()" />
  99.       </tr>
  100.     </table>
  101.     </br>
  102.     <td id="errCaptcha" class="errmsg"></td><input type="button" id="tes" onclick="pindah('http://www.google.com')" value="Silahkan" <br/>
  103.     </br>
  104.   </div>
  105. </body>
  106.  
  107. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement