0

I found this code to prevent double submit a form, but this code is not working as it should, it is disabling the submit button and changing the button value to "Please wait" but it is also submitting form.

<input type="submit" value="Submit" name="reply" onclick="this.disabled=true; this.value='Please Wait...';" /> 

How can I fix this? Thanks in advance

2
  • 1
    return false; at the end. Also, when should it submit if not when you click it? Commented Jan 17, 2018 at 15:23
  • Actually when the button is clicked it takes some time to refresh the form and if in that time the button is clicked the form is submitted again, so i just want the form to submit once either by disabling the button or totally hiding it Commented Jan 18, 2018 at 7:19

2 Answers 2

2
$("form").on("submit",function(e){ e.preventDefault(); $(this).find("[type='submit']").attr("disabled","disabled").attr("value","Please wait"); if(everything is ok) //you didn't specify what this is in your question. $(this).submit(); }); 
Sign up to request clarification or add additional context in comments.

2 Comments

what should be specified in this line if(everything is ok)
@Yaser what do you need to do before submitting? If you don't want to do anything, just delete the if statement
0

for anyone concerned i found this way and it worked for me

<input type="submit" value="Submit" name="reply_ticket" class="btn" onclick="this.style.visibility = 'hidden'" /> 

just add this to the button or input works either way

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.