ivana_andreevska

AV3 Validacija

Nov 5th, 2021
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <script src="script.js"></script>
  6.     <link rel="stylesheet" href="style.css">
  7.     <title>Practise</title>
  8. </head>
  9. <body>
  10. <p>Please input a number between 1 and 10:</p>
  11. <input id="numb" type="text">
  12. <button type="button" onclick="myFunction()">Submit</button>
  13. <p id="demo"></p>
  14. </body>
  15. <script src="script.js"></script>
  16. </html>
  17.  
  18. function myFunction() {
  19.     var x, text;
  20. //Get the value of input field with id="numb"
  21.     x = document.getElementById("numb").value;
  22. // If x is Not a Number or less than one or greater than 10
  23.     if (isNaN(x) || x < 1 || x > 10) {
  24.         text = "Input not valid";
  25.     } else {
  26.         text = "Input OK";
  27.     }
  28.     document.getElementById("demo").innerHTML = text;
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment