Want more features on Pastebin? Sign Up, it's FREE!
Guest

JS Form Validation

By: a guest on Oct 18th, 2012  |  syntax: HTML  |  size: 0.75 KB  |  views: 42  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <script>
  2. function deleteVal() {
  3.  
  4.                 var chk = document.getElementById('delete');
  5.  
  6.     // If the checkbox has been set to delete
  7.     if (chk.checked == true) {
  8.  
  9.         var ok=confirm("You are about to delete the selected images below.\nAre you sure you want to do this?");
  10.  
  11.         if (ok) {
  12.  
  13.             // Submit
  14.             return true;
  15.  
  16.         } else {
  17.  
  18.             // Don't submit
  19.             return false;
  20.  
  21.         }
  22.  
  23.     }
  24.  
  25.     // Delete box was not ticked so return true and submit form
  26.     return true;
  27.  
  28. }
  29.  
  30. </script>
  31.  
  32. <form action="" method="POST" onSubmit="return deleteVal();">
  33.   <label>Delete images?</label><input type="checkbox" name="delete" id="delete"/>
  34.   <input type="submit" name="submit" value="Submit" />
  35. </form>
clone this paste RAW Paste Data