radio-checkbox-select-demo.html 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Test for jQuery validate() plugin</title>
  6. <link rel="stylesheet" media="screen" href="css/screen.css">
  7. <script src="../lib/jquery.js"></script>
  8. <script src="../dist/jquery.validate.js"></script>
  9. <script>
  10. // only for demo purposes
  11. $.validator.setDefaults({
  12. submitHandler: function() {
  13. alert("submitted!");
  14. }
  15. });
  16. $(document).ready(function() {
  17. $("#form1").validate();
  18. $("#selecttest").validate();
  19. });
  20. </script>
  21. <style>
  22. .block {
  23. display: block;
  24. }
  25. form.cmxform label.error {
  26. display: none;
  27. }
  28. </style>
  29. </head>
  30. <body>
  31. <h1 id="banner"><a href="https://jqueryvalidation.org/">jQuery Validation Plugin</a> Demo</h1>
  32. <div id="main">
  33. <form class="cmxform" id="form1" method="get" action="">
  34. <fieldset>
  35. <legend>Validating a form with a radio and checkbox buttons</legend>
  36. <fieldset>
  37. <legend>Gender</legend>
  38. <label for="gender_male">
  39. <input type="radio" id="gender_male" value="m" name="gender" required>Male
  40. </label>
  41. <label for="gender_female">
  42. <input type="radio" id="gender_female" value="f" name="gender">Female
  43. </label>
  44. <label for="gender" class="error">Please select your gender</label>
  45. </fieldset>
  46. <fieldset>
  47. <legend>Family</legend>
  48. <label for="family_single">
  49. <input type="radio" id="family_single" value="s" name="family" required>Single
  50. </label>
  51. <label for="family_married">
  52. <input type="radio" id="family_married" value="m" name="family">Married
  53. </label>
  54. <label for="family_other">
  55. <input type="radio" id="family_other" value="o" name="family">Other
  56. </label>
  57. <label for="family" class="error">Please select your family status.</label>
  58. </fieldset>
  59. <p>
  60. <label for="agree">Please agree to our policy</label>
  61. <input type="checkbox" class="checkbox" id="agree" name="agree" required>
  62. <br>
  63. <label for="agree" class="error block">Please agree to our policy!</label>
  64. </p>
  65. <fieldset>
  66. <legend>Spam</legend>
  67. <label for="spam_email">
  68. <input type="checkbox" class="checkbox" id="spam_email" value="email" name="spam[]" required minlength="2">Spam via E-Mail
  69. </label>
  70. <label for="spam_phone">
  71. <input type="checkbox" class="checkbox" id="spam_phone" value="phone" name="spam[]">Spam via Phone
  72. </label>
  73. <label for="spam_mail">
  74. <input type="checkbox" class="checkbox" id="spam_mail" value="mail" name="spam[]">Spam via Mail
  75. </label>
  76. <label for="spam[]" class="error">Please select at least two types of spam.</label>
  77. </fieldset>
  78. <p>
  79. <input class="submit" type="submit" value="Submit">
  80. </p>
  81. </fieldset>
  82. </form>
  83. <form id="selecttest">
  84. <h2>Some tests with selects</h2>
  85. <p>
  86. <label for="jungle">Please select a jungle noun</label>
  87. <br>
  88. <select id="jungle" name="jungle" title="Please select something!" required>
  89. <option value=""></option>
  90. <option value="1">Buga</option>
  91. <option value="2">Baga</option>
  92. <option value="3">Oi</option>
  93. </select>
  94. </p>
  95. <p>
  96. <label for="fruit">Please select at least two fruits</label>
  97. <br>
  98. <select id="fruit" name="fruit" title="Please select at least two fruits" required minlength="2" multiple="multiple">
  99. <option value="b">Banana</option>
  100. <option value="a">Apple</option>
  101. <option value="p">Peach</option>
  102. <option value="t">Turtle</option>
  103. </select>
  104. </p>
  105. <p>
  106. <label for="vegetables">Please select no more than two vergetables</label>
  107. <br>
  108. <select id="vegetables" name="vegetables" title="Please select no more than two vergetables" required maxlength="2" multiple="multiple">
  109. <option value="p">Potato</option>
  110. <option value="t">Tomato</option>
  111. <option value="s">Salad</option>
  112. </select>
  113. </p>
  114. <p>
  115. <label for="cars">Please select at least two cars, but no more than three</label>
  116. <br>
  117. <select id="cars" name="cars" title="Please select at least two cars, but no more than three" required rangelength="[2,3]" multiple="multiple">
  118. <option value="m_sl">Mercedes SL</option>
  119. <option value="o_c">Opel Corsa</option>
  120. <option value="vw_p">VW Polo</option>
  121. <option value="t_s">Titanic Skoda</option>
  122. </select>
  123. </p>
  124. <p>
  125. <input type="submit" value="Validate Selecttests">
  126. </p>
  127. </form>
  128. <a href="index.html">Back to main page</a>
  129. </div>
  130. </body>
  131. </html>