Advertisement
Guest User

Validating data with JavaScript

a guest
Oct 30th, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <p>Guess my age:</p>
  6.  
  7. <input id="age" type="number">
  8.  
  9. <button type="button" onclick="myFunction()">Enter</button>
  10.  
  11. <p id="abc"></p>
  12.  
  13. <script>
  14. function myFunction() {
  15. var x, text;
  16.  
  17. x = document.getElementById("age").value;
  18.  
  19. if (isNaN(x) || x < 19) {
  20. text = "Too young!";
  21. }
  22. else if (isNaN(x) || x > 19) {
  23. text = "Too old!";
  24. }
  25. else {
  26. text = "Correct!";
  27. }
  28. document.getElementById("abc").innerHTML = text;
  29. }
  30. </script>
  31.  
  32. </body>
  33. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement