s

jquery how to make input submit button in a form submit only once edit button Edit

author
Murugan Andezuthu Dharmaratnam | calendar 09 December 2020 | 1900

I have a form with a submit button, I need to disable the button once it's clicked so the user can't click it again. I tried jquery code below

$("#SubmitButtonsId").attr("disabled", "disabled"); 

document.getElementById('SubmitButtonsId').disabled = 'true'; 
I tried using both jQuery and JavaScript and it's disabling the button but the form is not being submitted.

Solution

The solution is to disable input button of the form on submit

  <script>
  
  $('#contactform').submit(function(){
    $(this).find(':input[type=submit]').prop('disabled', true);
});

  </script>