javascript - Form Validation


SUBMITTED BY: Guest

DATE: Feb. 24, 2014, 7:32 p.m.

FORMAT: HTML

SIZE: 1.8 kB

HITS: 1254

  1. <!DOCTYPE html>
  2. <html>
  3. <head><title> Validation </title>
  4. <script>
  5. function checking() {
  6. if (document.test.iud.value.length < 2 || document.test.iud.value.length > 3) {
  7. window.alert("User ID must have 2 to 3 characters only");
  8. return false;
  9. }
  10. else {
  11. if (document.test.price.value < 1 || !isNumber(document.test.price.value)) {
  12. window.alert("The price must be a positive value");
  13. return false;
  14. }
  15. else {
  16. if (document.test.quan.value < 20) {
  17. window.alert("The minimum amount of items is 20.")
  18. return false;
  19. }
  20. else {
  21. if (document.test.status.value == undefined) {
  22. window.alert("You must select a status.");
  23. return false;
  24. }
  25. else
  26. return true;
  27. }
  28. }
  29. }
  30. }
  31. function isNumber(n) {
  32. return !isNaN(parseFloat(n)) && isFinite(n);
  33. }
  34. </script>
  35. </head>
  36. <body>
  37. <form name=test onsubmit="return checking()">
  38. Enter User ID <br><input type=text name=iud size=30><br>
  39. Enter price of items <br><input type=text name=price size=30><br>
  40. Enter amount of items <br><input type=text name=quan size=30><br>
  41. Select Status <br><input type="radio" value="1" name="status"/>Normal
  42. <br><input type="radio" value="1" name="status"/>Advance
  43. <br>
  44. <input type=submit value="Submit">
  45. <input type=reset value="clear all">
  46. </form>
  47. </body>
  48. </html>

comments powered by Disqus