Advertisement
Guest User

check-month

a guest
Apr 23rd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 0.68 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <input type="number" id="myNumber" value="">
  6.  
  7. <p>Enter the month.</p>
  8.  
  9. <button onclick="myFunction()">Check if entered month is valid</button>
  10.  
  11. <script>
  12.     function myFunction() {
  13.  
  14.         // get the input typed by user
  15.         var month = document.getElementById("myNumber");
  16.  
  17.         // convert the value to a number
  18.         var monthAsNumber = Number(month.value);
  19.  
  20.         // check that the value is between 1 and 12
  21.         if(monthAsNumber >= 1 && monthAsNumber <= 12) {
  22.            alert('The month introduced is valid');
  23.         } else {
  24.             alert('Your value is out of range');
  25.         }
  26.     }
  27. </script>
  28.  
  29. </body>
  30. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement