0

So this is how my form looks like:

<form method="post" action="kudos.php">
    <input type="hidden" name="hidden_id" value="<?php echo $id ?>">
    <input type="hidden" name="hidden_ident" value="<?php echo $myIdent ?>">
    <button type="submit" id="kudosBtn" class="kudosBtn"></button>
</form>

If the user press the submit button quick 10 times, the form will submit 10 times also. I tried adding onclick="kudosClick()" to the submit button and the script below, but that doesn't do anything:

<script>
function kudosClick() {
    $(this).attr("disabled", "disabled");
}
</script>

Any tips on how to fix this?

  • Add required on fields and on submit clear the inputs. It is also very unclear how are you even submitting, action says action="kudos.php" witch means on regular POST submit ion it should go to that page... – ikiK Mar 25 '21 at 15:09

1 Answers1

1

This is assuming you are using jQuery, based on the code you provided:

$("#kudosBtn").click(function() {
  $(this).prop("disabled", "true");
})

$(this) will now be referencing $("#kudosBtn"), which is what you want.

AntonyMN
  • 660
  • 6
  • 18