0
<form id="login" method='post' action='membership.php'>
    <b>Email</b><br><br>
    <input class="form" type='text' name='email2' id='email2'><br><br>
    <b>Password</b><br><br>
    <input class="form" type='password' name='password2' id='password2'><br><br>
    <input class="submitborder" id='submit2' type='submit' name='submit2' value='Submit'>
</form>

<script>
$(document).ready(function () {
    $("#submit2").on("click", function() {
        $(this).attr("disabled", "disabled");
        Submitting();
    });
});

function Submitting() {
    setTimeout('$("#submit2").removeAttr("disabled")', 10000);
}

function PreventDouble(event) {
    event.preventDefault();
}
</script>

<?php
echo "<a href='construction.php' onclick='PreventDouble(this)'></a>";
?>

I've read a few forum pages etc ... and they suggest disabling using jQuery or AJAX. When I disable though, I doesn't submit the form data anymore. But will disable the button accordingly.

For the hyperlink, because it sends user to another page, then disables, it's hard to judge if onclick='PreventDouble(this);' is working.

I also would like to apologize as I am a newb when it comes to Javascript, jQuery, or AJAX.

UPDATE: May I also mention I'm newb at this forum posting. Um. One last note is the disabling of form button. I use this code in another area of my website that doesn't click properly on computer. As if it seems to be on a wait before it processes my Javascript/jQuery/AJAX scripts? I dunno.

I admit defeat to Javascript/jQuery/AJAX x_x

Don't Panic
  • 13,965
  • 5
  • 32
  • 51
PowerThree
  • 13
  • 5
  • Your form fields do not match your Javascript / jQuery selectors. Fix your code. – Eduardo Escobar Apr 19 '20 at 17:59
  • I think you are trying to prevent the form being submitted twice, eg by clicking the button 2 times quickly? The code you have shown will do that - it disables the button, but does not stop the form submission. Depending on how long the network request to submit your form takes, your `Submitting()` may or may not actually run. There is no need for it though - when your form POST actually happens, the browser will leave this form page and the button disappears anyway. Re-enabling it just before that happens only allows another click, if someone is determined. – Don't Panic Apr 20 '20 at 03:52
  • No the second I incorporate either that code or this code onclick='this.disabled=true' it disables form submission. So then im left having to submit the form using javascript instead php? if that makes sense @_@ – PowerThree Apr 20 '20 at 15:12
  • Does this answer your question? [jquery disable submit button on form submission](https://stackoverflow.com/questions/5445431/jquery-disable-submit-button-on-form-submission) – Don't Panic Apr 21 '20 at 00:27

1 Answers1

0

I may be wrong as I am not familiar with PHP, but it doesn't look like the PreventDouble(this) method get called upon form submission. You can try putting the function inside the click event handler instead. Or better yet, just put the event.preventDefault() line there.

alexako
  • 122
  • 7
  • im trying to prevent over clicking of forms, links, and buttons. In the php code it echo's(prints) html code that has javascript function PreventDouble() in it.. The question I wonder is if this code is right.. For the javascript function in reference to hyperlinks. It has nothing to do with the form submission. I have two different questions here. @_@ But I will try this.. "click event handler" – PowerThree Apr 20 '20 at 15:20