daily pastebin goal
39%
SHARE
TWEET

Untitled

a guest Jan 18th, 2019 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2. <head>
  3. <script src="LiveValidation.js"></script>
  4. <style type="text/css">
  5. .LV_validation_message{
  6.     font-weight:bold;
  7.     margin:0 0 0 5px;
  8. }
  9.  
  10. .LV_valid {
  11.     color:#00CC00;
  12. }
  13.  
  14. .LV_invalid {
  15.     color:#CC0000;
  16. }
  17.  
  18. .LV_valid_field,
  19. input.LV_valid_field:hover,
  20. input.LV_valid_field:active,
  21. textarea.LV_valid_field:hover,
  22. textarea.LV_valid_field:active {
  23.     border: 1px solid #00CC00;
  24. }
  25.  
  26. .LV_invalid_field,
  27. input.LV_invalid_field:hover,
  28. input.LV_invalid_field:active,
  29. textarea.LV_invalid_field:hover,
  30. textarea.LV_invalid_field:active {
  31.     border: 1px solid #CC0000;
  32. }
  33. </style>
  34. </head>
  35. <body>
  36. <form method=post action="#">
  37. <p><label for="field1" class="displayBlock">Test Field:</label><input type="text" id="field1" /></p>
  38. <p><label for="chk_group" class="displayBlock">Acceptance (required):</label><br/>
  39. <input type="checkbox" id="chk_group" value="value1" />Value 1<br />
  40. <input type="checkbox" id="chk_group" value="value2" />Value 2<br />
  41. <input type="checkbox" id="chk_group" value="value3" />Value 3<br />
  42. <input type="checkbox" id="chk_group" value="value4" />Value 4<br />
  43. <input type="checkbox" id="chk_group" value="value5" />Value 5<br />
  44. <input type="checkbox" id="chk_group" value="value6" />Value 6<br /></p>
  45. <p><input type="submit" class="submit" value="Test me!" /></p>
  46. </form>
  47.  <script type="text/javascript">
  48.  function isValidField(value){
  49.  var list=document.getElementById("field1");
  50.  var selectd_items=0;
  51.  
  52. for(i=0;i<list.length;i++){
  53. if(list[i].selected){
  54. selectd_items++;
  55. }
  56. }
  57.  cbcount =(selectd_items >2) ?  true :  false;
  58.  return cbcount;
  59.  };
  60.  
  61.                 var chk_group = new LiveValidation( 'chk_group', {onlyOnSubmit: true } );
  62.                 chk_group.add(Validate.Presence);
  63.                 chk_group.add( Validate.Custom, { against: function(value){ return isValidField(value) }, failureMessage: "Try Again" } );
  64.  
  65.  
  66.           var automaticOnSubmit = chk_group.form.onsubmit;
  67.           chk_group.form.onsubmit = function(){
  68.               var valid = automaticOnSubmit();
  69.               if(valid)alert('The form is valid!');
  70.             return false;
  71.           }
  72.           </script>
  73. </body>
  74. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top