Advertisement
Guest User

JS - Formularze

a guest
Oct 18th, 2017
609
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3.   <head>
  4.     <meta charset="utf-8">
  5.     <title>Form</title>
  6.     <style>
  7.       body {
  8.         background-color: #3e3e3e;
  9.         color: #e3e3e3;
  10.       }
  11.     </style>
  12.   </head>
  13.   <body>
  14.  
  15.     <form name="form1" onsubmit="return weryfikacja()">
  16.       Imie i nazwisko: <input type="text" name="imie">
  17.       <br>
  18.       Wiek: <input type="number" name="wiek">
  19.       <br>
  20.       <input type="submit" value="ok">
  21.     </form>
  22.  
  23.     <form name="login" onsubmit="return logowanie()">
  24.       Nazwa: <input type="text" name="nazwa"><br>
  25.       Haslo: <input type="password" name="haslo"><br>
  26.       <input type="submit" value="Zaloguj">
  27.     </form>
  28.  
  29.     <script>
  30.  
  31.       //alert(document.getElementById("jeden").children[2].value);
  32.       function weryfikacja(){
  33.         var wiek = parseInt( document.forms['form1']['wiek'].value );
  34.  
  35.         if( isNaN(wiek) ){
  36.           alert("Nie podales wieku!");
  37.           return false;
  38.         }
  39.         if( wiek < 18 ){
  40.           alert("Jestes nie pelnoletni");
  41.           return false;
  42.         }else {
  43.           var imie = document.forms['form1']['imie'].value;
  44.           alert("Witaj: " + imie);
  45.         }
  46.       }
  47.  
  48.       function logowanie(){
  49.         var nickElem = document.forms['login']['nazwa'];
  50.         var passElem = document.forms['login']['haslo'];
  51.         if(nickElem.value.length < 3 ){
  52.           nickElem.style.backgroundColor = "red";
  53.  
  54.           setTimeout( function(){
  55.             nickElem.style.backgroundColor = "white";
  56.           }, 500); //500ms = 0.5s
  57.  
  58.           return false;
  59.         }
  60.  
  61.         if(passElem.value.length < 6 ){
  62.           passElem.style.backgroundColor = "red";
  63.           setTimeout( function(){
  64.             passElem.style.backgroundColor = "white";
  65.           }, 500); //500ms = 0.5s
  66.           return false;
  67.         }
  68.       }
  69.  
  70.     </script>
  71.   </body>
  72. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement