Advertisement
michaelyuen

Untitled

Apr 15th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <form id="myform" action="http://ymlp.com/subscribe.php?id=<?= $userid; ?" type="POST">
  2.     <input type="hidden" id="userid" name="userid" value="<?= $userid; ?>">
  3.     <input type="checkbox" id="accept" name="accept" value="accept">
  4.     <input type="submit" name="submit" id="submit" value="submit">
  5. </form>
  6. <script
  7.   src="https://code.jquery.com/jquery-3.3.1.min.js"
  8.   integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
  9.   crossorigin="anonymous"></script>
  10. <script>
  11.     $('#submit').on('click', function(e){
  12.         e.preventDefault();
  13.         // check if checkbox is checked
  14.         if ($('#accept').is('checked')) {
  15.             var userid = $('#userid').val();
  16.             $.ajax({
  17.                 type: "POST",
  18.                 url: "myphp.php",
  19.                 data: {'userid' : userid},
  20.                 success: function(data) {
  21.                     if ($.trim(data) == 'success') {
  22.                         $('#myform').submit();
  23.                     }
  24.                 }
  25.             });
  26.         }
  27.     });
  28. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement