Button value to be changed back to original value on timeout (form double submit)





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







8















I am trying to fix a form double submit by disabling the submit button temporarily and changing the submit button value to "processing..." so the user knows what is going on.



The disable works onClick and the "Submit" value changes to "processing...", however I am unable to change the value back to "Submit" after the setTimeout function has ended.



Does anyone know how I could go about doing this?






$(function() {
$("#submit_btn").click(function() {
$("#submit_btn").attr("disabled", "disabled");
this.value = "Processing...";
setTimeout(function() {
this.value = "Submit"; //<- this line doesn't work
$("#submit_btn").removeAttr("disabled");
}, 5000);
});
});

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input id="submit_btn" type="submit" value="Submit" />












share|improve this question































    8















    I am trying to fix a form double submit by disabling the submit button temporarily and changing the submit button value to "processing..." so the user knows what is going on.



    The disable works onClick and the "Submit" value changes to "processing...", however I am unable to change the value back to "Submit" after the setTimeout function has ended.



    Does anyone know how I could go about doing this?






    $(function() {
    $("#submit_btn").click(function() {
    $("#submit_btn").attr("disabled", "disabled");
    this.value = "Processing...";
    setTimeout(function() {
    this.value = "Submit"; //<- this line doesn't work
    $("#submit_btn").removeAttr("disabled");
    }, 5000);
    });
    });

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <input id="submit_btn" type="submit" value="Submit" />












    share|improve this question



























      8












      8








      8


      2






      I am trying to fix a form double submit by disabling the submit button temporarily and changing the submit button value to "processing..." so the user knows what is going on.



      The disable works onClick and the "Submit" value changes to "processing...", however I am unable to change the value back to "Submit" after the setTimeout function has ended.



      Does anyone know how I could go about doing this?






      $(function() {
      $("#submit_btn").click(function() {
      $("#submit_btn").attr("disabled", "disabled");
      this.value = "Processing...";
      setTimeout(function() {
      this.value = "Submit"; //<- this line doesn't work
      $("#submit_btn").removeAttr("disabled");
      }, 5000);
      });
      });

      <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      <input id="submit_btn" type="submit" value="Submit" />












      share|improve this question
















      I am trying to fix a form double submit by disabling the submit button temporarily and changing the submit button value to "processing..." so the user knows what is going on.



      The disable works onClick and the "Submit" value changes to "processing...", however I am unable to change the value back to "Submit" after the setTimeout function has ended.



      Does anyone know how I could go about doing this?






      $(function() {
      $("#submit_btn").click(function() {
      $("#submit_btn").attr("disabled", "disabled");
      this.value = "Processing...";
      setTimeout(function() {
      this.value = "Submit"; //<- this line doesn't work
      $("#submit_btn").removeAttr("disabled");
      }, 5000);
      });
      });

      <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      <input id="submit_btn" type="submit" value="Submit" />








      $(function() {
      $("#submit_btn").click(function() {
      $("#submit_btn").attr("disabled", "disabled");
      this.value = "Processing...";
      setTimeout(function() {
      this.value = "Submit"; //<- this line doesn't work
      $("#submit_btn").removeAttr("disabled");
      }, 5000);
      });
      });

      <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      <input id="submit_btn" type="submit" value="Submit" />





      $(function() {
      $("#submit_btn").click(function() {
      $("#submit_btn").attr("disabled", "disabled");
      this.value = "Processing...";
      setTimeout(function() {
      this.value = "Submit"; //<- this line doesn't work
      $("#submit_btn").removeAttr("disabled");
      }, 5000);
      });
      });

      <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      <input id="submit_btn" type="submit" value="Submit" />






      javascript jquery html






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 1 at 6:49









      Arend

      3,53012137




      3,53012137










      asked Apr 1 at 5:50









      RobertRobert

      616




      616
























          5 Answers
          5






          active

          oldest

          votes


















          6














          Just change this to $("#submit_btn") and it works:






          $(function() {
          $("#submit_btn").click(function() {
          $("#submit_btn").attr("disabled", "disabled");
          $("#submit_btn").val("Processing...");
          setTimeout(function() {
          $("#submit_btn").val("Submit");
          $("#submit_btn").removeAttr("disabled");
          }, 5000);
          });
          });

          <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
          <input id="submit_btn" type="submit" value="Submit" />





          The issue was that your functions were interfering with this. You could have done self = this which would have had the same effect:






          $(function() {
          $("#submit_btn").click(function() {
          var self = this;
          $(self).attr("disabled", "disabled");
          $(self).val("Processing...");
          setTimeout(function() {
          $(self).val("Submit");
          $(self).removeAttr("disabled");
          }, 5000);
          });
          });

          <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
          <input id="submit_btn" type="submit" value="Submit" />





          Or you could have used event.target:






          $(function() {
          $("#submit_btn").click(function(event) {
          $(event.target).attr("disabled", "disabled");
          $(event.target).val("Processing...");
          setTimeout(function() {
          $(event.target).val("Submit");
          $(event.target).removeAttr("disabled");
          }, 5000);
          });
          });

          <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
          <input id="submit_btn" type="submit" value="Submit" />








          share|improve this answer





















          • 1





            Explanation is needed to understand why you did what you did (and I didn't downvote).

            – LGSon
            Apr 1 at 6:03








          • 1





            Oh yes @LGSon - I'll add that.

            – Jack Bashford
            Apr 1 at 6:03






          • 1





            Awesome thanks man. I swear I tried that approach before I posted this question... must have forgotten a semi colon or something lol, rookie mistake. I'll accept your answer in 3 minutes when stackoverflow allows me. Cheers!

            – Robert
            Apr 1 at 6:04



















          2














          you just need to replace that line with the following code:
          $("#submit_btn").val("Submit");



          you should use val function to change the text of the button.






          share|improve this answer































            2














             $(function() {
            $("#submit_btn").click(function(event) {
            $('button').button({ loadingText: 'Processing..' });
            $('#submit_btn').button('loading');
            //after submit stuff put below line to reset;
            $('#submit_btn').button('reset');
            });
            });


            above code work best when you used
            html button in place of input type button
            Note-- To Show Spin Icon inside Button put
            font-awesome or any other icon in place of Processing.. or both in loadingText object






            share|improve this answer


























            • it prevent multiple click (submit) until first click event completed by... disabling button by default ,,

              – Haider Ali
              Apr 1 at 7:09



















            1














            $(document).ready(function() {
            $(function() {
            $("#submit_btn").click(function() {
            $("#submit_btn").attr("disabled", "disabled");
            this.value = "Processing...";
            outerthis = this;
            setTimeout(function() {
            outerthis.value = "Submit";
            $("#submit_btn").removeAttr("disabled");
            }, 5000);
            });
            });
            });





            share|improve this answer

































              0














              Problem about the wrong usage of this keyword inside setTimeout() has already been explained. However, if you are able to use arrow function expressions (ES6 feature), that won't be a problem:




              An arrow function expression is a syntactically compact alternative to a regular function expression, although without its own bindings to the this, arguments, super, or new.target keywords.




              Using this feature, your code can be simplified a little as shown on next example:






              $("#submit_btn").click(function()
              {
              $(this).attr("disabled", "disabled").val("Processing...");

              setTimeout(
              () => $(this).val("Submit").removeAttr("disabled"),
              5000
              );
              });

              <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
              <input id="submit_btn" type="submit" value="Submit" />








              share|improve this answer


























                Your Answer






                StackExchange.ifUsing("editor", function () {
                StackExchange.using("externalEditor", function () {
                StackExchange.using("snippets", function () {
                StackExchange.snippets.init();
                });
                });
                }, "code-snippets");

                StackExchange.ready(function() {
                var channelOptions = {
                tags: "".split(" "),
                id: "1"
                };
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function() {
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled) {
                StackExchange.using("snippets", function() {
                createEditor();
                });
                }
                else {
                createEditor();
                }
                });

                function createEditor() {
                StackExchange.prepareEditor({
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader: {
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                },
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                });


                }
                });














                draft saved

                draft discarded


















                StackExchange.ready(
                function () {
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55448780%2fbutton-value-to-be-changed-back-to-original-value-on-timeout-form-double-submit%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                5 Answers
                5






                active

                oldest

                votes








                5 Answers
                5






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                6














                Just change this to $("#submit_btn") and it works:






                $(function() {
                $("#submit_btn").click(function() {
                $("#submit_btn").attr("disabled", "disabled");
                $("#submit_btn").val("Processing...");
                setTimeout(function() {
                $("#submit_btn").val("Submit");
                $("#submit_btn").removeAttr("disabled");
                }, 5000);
                });
                });

                <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
                <input id="submit_btn" type="submit" value="Submit" />





                The issue was that your functions were interfering with this. You could have done self = this which would have had the same effect:






                $(function() {
                $("#submit_btn").click(function() {
                var self = this;
                $(self).attr("disabled", "disabled");
                $(self).val("Processing...");
                setTimeout(function() {
                $(self).val("Submit");
                $(self).removeAttr("disabled");
                }, 5000);
                });
                });

                <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
                <input id="submit_btn" type="submit" value="Submit" />





                Or you could have used event.target:






                $(function() {
                $("#submit_btn").click(function(event) {
                $(event.target).attr("disabled", "disabled");
                $(event.target).val("Processing...");
                setTimeout(function() {
                $(event.target).val("Submit");
                $(event.target).removeAttr("disabled");
                }, 5000);
                });
                });

                <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
                <input id="submit_btn" type="submit" value="Submit" />








                share|improve this answer





















                • 1





                  Explanation is needed to understand why you did what you did (and I didn't downvote).

                  – LGSon
                  Apr 1 at 6:03








                • 1





                  Oh yes @LGSon - I'll add that.

                  – Jack Bashford
                  Apr 1 at 6:03






                • 1





                  Awesome thanks man. I swear I tried that approach before I posted this question... must have forgotten a semi colon or something lol, rookie mistake. I'll accept your answer in 3 minutes when stackoverflow allows me. Cheers!

                  – Robert
                  Apr 1 at 6:04
















                6














                Just change this to $("#submit_btn") and it works:






                $(function() {
                $("#submit_btn").click(function() {
                $("#submit_btn").attr("disabled", "disabled");
                $("#submit_btn").val("Processing...");
                setTimeout(function() {
                $("#submit_btn").val("Submit");
                $("#submit_btn").removeAttr("disabled");
                }, 5000);
                });
                });

                <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
                <input id="submit_btn" type="submit" value="Submit" />





                The issue was that your functions were interfering with this. You could have done self = this which would have had the same effect:






                $(function() {
                $("#submit_btn").click(function() {
                var self = this;
                $(self).attr("disabled", "disabled");
                $(self).val("Processing...");
                setTimeout(function() {
                $(self).val("Submit");
                $(self).removeAttr("disabled");
                }, 5000);
                });
                });

                <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
                <input id="submit_btn" type="submit" value="Submit" />





                Or you could have used event.target:






                $(function() {
                $("#submit_btn").click(function(event) {
                $(event.target).attr("disabled", "disabled");
                $(event.target).val("Processing...");
                setTimeout(function() {
                $(event.target).val("Submit");
                $(event.target).removeAttr("disabled");
                }, 5000);
                });
                });

                <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
                <input id="submit_btn" type="submit" value="Submit" />








                share|improve this answer





















                • 1





                  Explanation is needed to understand why you did what you did (and I didn't downvote).

                  – LGSon
                  Apr 1 at 6:03








                • 1





                  Oh yes @LGSon - I'll add that.

                  – Jack Bashford
                  Apr 1 at 6:03






                • 1





                  Awesome thanks man. I swear I tried that approach before I posted this question... must have forgotten a semi colon or something lol, rookie mistake. I'll accept your answer in 3 minutes when stackoverflow allows me. Cheers!

                  – Robert
                  Apr 1 at 6:04














                6












                6








                6







                Just change this to $("#submit_btn") and it works:






                $(function() {
                $("#submit_btn").click(function() {
                $("#submit_btn").attr("disabled", "disabled");
                $("#submit_btn").val("Processing...");
                setTimeout(function() {
                $("#submit_btn").val("Submit");
                $("#submit_btn").removeAttr("disabled");
                }, 5000);
                });
                });

                <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
                <input id="submit_btn" type="submit" value="Submit" />





                The issue was that your functions were interfering with this. You could have done self = this which would have had the same effect:






                $(function() {
                $("#submit_btn").click(function() {
                var self = this;
                $(self).attr("disabled", "disabled");
                $(self).val("Processing...");
                setTimeout(function() {
                $(self).val("Submit");
                $(self).removeAttr("disabled");
                }, 5000);
                });
                });

                <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
                <input id="submit_btn" type="submit" value="Submit" />





                Or you could have used event.target:






                $(function() {
                $("#submit_btn").click(function(event) {
                $(event.target).attr("disabled", "disabled");
                $(event.target).val("Processing...");
                setTimeout(function() {
                $(event.target).val("Submit");
                $(event.target).removeAttr("disabled");
                }, 5000);
                });
                });

                <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
                <input id="submit_btn" type="submit" value="Submit" />








                share|improve this answer















                Just change this to $("#submit_btn") and it works:






                $(function() {
                $("#submit_btn").click(function() {
                $("#submit_btn").attr("disabled", "disabled");
                $("#submit_btn").val("Processing...");
                setTimeout(function() {
                $("#submit_btn").val("Submit");
                $("#submit_btn").removeAttr("disabled");
                }, 5000);
                });
                });

                <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
                <input id="submit_btn" type="submit" value="Submit" />





                The issue was that your functions were interfering with this. You could have done self = this which would have had the same effect:






                $(function() {
                $("#submit_btn").click(function() {
                var self = this;
                $(self).attr("disabled", "disabled");
                $(self).val("Processing...");
                setTimeout(function() {
                $(self).val("Submit");
                $(self).removeAttr("disabled");
                }, 5000);
                });
                });

                <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
                <input id="submit_btn" type="submit" value="Submit" />





                Or you could have used event.target:






                $(function() {
                $("#submit_btn").click(function(event) {
                $(event.target).attr("disabled", "disabled");
                $(event.target).val("Processing...");
                setTimeout(function() {
                $(event.target).val("Submit");
                $(event.target).removeAttr("disabled");
                }, 5000);
                });
                });

                <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
                <input id="submit_btn" type="submit" value="Submit" />








                $(function() {
                $("#submit_btn").click(function() {
                $("#submit_btn").attr("disabled", "disabled");
                $("#submit_btn").val("Processing...");
                setTimeout(function() {
                $("#submit_btn").val("Submit");
                $("#submit_btn").removeAttr("disabled");
                }, 5000);
                });
                });

                <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
                <input id="submit_btn" type="submit" value="Submit" />





                $(function() {
                $("#submit_btn").click(function() {
                $("#submit_btn").attr("disabled", "disabled");
                $("#submit_btn").val("Processing...");
                setTimeout(function() {
                $("#submit_btn").val("Submit");
                $("#submit_btn").removeAttr("disabled");
                }, 5000);
                });
                });

                <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
                <input id="submit_btn" type="submit" value="Submit" />





                $(function() {
                $("#submit_btn").click(function() {
                var self = this;
                $(self).attr("disabled", "disabled");
                $(self).val("Processing...");
                setTimeout(function() {
                $(self).val("Submit");
                $(self).removeAttr("disabled");
                }, 5000);
                });
                });

                <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
                <input id="submit_btn" type="submit" value="Submit" />





                $(function() {
                $("#submit_btn").click(function() {
                var self = this;
                $(self).attr("disabled", "disabled");
                $(self).val("Processing...");
                setTimeout(function() {
                $(self).val("Submit");
                $(self).removeAttr("disabled");
                }, 5000);
                });
                });

                <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
                <input id="submit_btn" type="submit" value="Submit" />





                $(function() {
                $("#submit_btn").click(function(event) {
                $(event.target).attr("disabled", "disabled");
                $(event.target).val("Processing...");
                setTimeout(function() {
                $(event.target).val("Submit");
                $(event.target).removeAttr("disabled");
                }, 5000);
                });
                });

                <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
                <input id="submit_btn" type="submit" value="Submit" />





                $(function() {
                $("#submit_btn").click(function(event) {
                $(event.target).attr("disabled", "disabled");
                $(event.target).val("Processing...");
                setTimeout(function() {
                $(event.target).val("Submit");
                $(event.target).removeAttr("disabled");
                }, 5000);
                });
                });

                <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
                <input id="submit_btn" type="submit" value="Submit" />






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Apr 1 at 6:06

























                answered Apr 1 at 6:01









                Jack BashfordJack Bashford

                16.6k51848




                16.6k51848








                • 1





                  Explanation is needed to understand why you did what you did (and I didn't downvote).

                  – LGSon
                  Apr 1 at 6:03








                • 1





                  Oh yes @LGSon - I'll add that.

                  – Jack Bashford
                  Apr 1 at 6:03






                • 1





                  Awesome thanks man. I swear I tried that approach before I posted this question... must have forgotten a semi colon or something lol, rookie mistake. I'll accept your answer in 3 minutes when stackoverflow allows me. Cheers!

                  – Robert
                  Apr 1 at 6:04














                • 1





                  Explanation is needed to understand why you did what you did (and I didn't downvote).

                  – LGSon
                  Apr 1 at 6:03








                • 1





                  Oh yes @LGSon - I'll add that.

                  – Jack Bashford
                  Apr 1 at 6:03






                • 1





                  Awesome thanks man. I swear I tried that approach before I posted this question... must have forgotten a semi colon or something lol, rookie mistake. I'll accept your answer in 3 minutes when stackoverflow allows me. Cheers!

                  – Robert
                  Apr 1 at 6:04








                1




                1





                Explanation is needed to understand why you did what you did (and I didn't downvote).

                – LGSon
                Apr 1 at 6:03







                Explanation is needed to understand why you did what you did (and I didn't downvote).

                – LGSon
                Apr 1 at 6:03






                1




                1





                Oh yes @LGSon - I'll add that.

                – Jack Bashford
                Apr 1 at 6:03





                Oh yes @LGSon - I'll add that.

                – Jack Bashford
                Apr 1 at 6:03




                1




                1





                Awesome thanks man. I swear I tried that approach before I posted this question... must have forgotten a semi colon or something lol, rookie mistake. I'll accept your answer in 3 minutes when stackoverflow allows me. Cheers!

                – Robert
                Apr 1 at 6:04





                Awesome thanks man. I swear I tried that approach before I posted this question... must have forgotten a semi colon or something lol, rookie mistake. I'll accept your answer in 3 minutes when stackoverflow allows me. Cheers!

                – Robert
                Apr 1 at 6:04













                2














                you just need to replace that line with the following code:
                $("#submit_btn").val("Submit");



                you should use val function to change the text of the button.






                share|improve this answer




























                  2














                  you just need to replace that line with the following code:
                  $("#submit_btn").val("Submit");



                  you should use val function to change the text of the button.






                  share|improve this answer


























                    2












                    2








                    2







                    you just need to replace that line with the following code:
                    $("#submit_btn").val("Submit");



                    you should use val function to change the text of the button.






                    share|improve this answer













                    you just need to replace that line with the following code:
                    $("#submit_btn").val("Submit");



                    you should use val function to change the text of the button.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Apr 1 at 7:02









                    AnaghaAnagha

                    673




                    673























                        2














                         $(function() {
                        $("#submit_btn").click(function(event) {
                        $('button').button({ loadingText: 'Processing..' });
                        $('#submit_btn').button('loading');
                        //after submit stuff put below line to reset;
                        $('#submit_btn').button('reset');
                        });
                        });


                        above code work best when you used
                        html button in place of input type button
                        Note-- To Show Spin Icon inside Button put
                        font-awesome or any other icon in place of Processing.. or both in loadingText object






                        share|improve this answer


























                        • it prevent multiple click (submit) until first click event completed by... disabling button by default ,,

                          – Haider Ali
                          Apr 1 at 7:09
















                        2














                         $(function() {
                        $("#submit_btn").click(function(event) {
                        $('button').button({ loadingText: 'Processing..' });
                        $('#submit_btn').button('loading');
                        //after submit stuff put below line to reset;
                        $('#submit_btn').button('reset');
                        });
                        });


                        above code work best when you used
                        html button in place of input type button
                        Note-- To Show Spin Icon inside Button put
                        font-awesome or any other icon in place of Processing.. or both in loadingText object






                        share|improve this answer


























                        • it prevent multiple click (submit) until first click event completed by... disabling button by default ,,

                          – Haider Ali
                          Apr 1 at 7:09














                        2












                        2








                        2







                         $(function() {
                        $("#submit_btn").click(function(event) {
                        $('button').button({ loadingText: 'Processing..' });
                        $('#submit_btn').button('loading');
                        //after submit stuff put below line to reset;
                        $('#submit_btn').button('reset');
                        });
                        });


                        above code work best when you used
                        html button in place of input type button
                        Note-- To Show Spin Icon inside Button put
                        font-awesome or any other icon in place of Processing.. or both in loadingText object






                        share|improve this answer















                         $(function() {
                        $("#submit_btn").click(function(event) {
                        $('button').button({ loadingText: 'Processing..' });
                        $('#submit_btn').button('loading');
                        //after submit stuff put below line to reset;
                        $('#submit_btn').button('reset');
                        });
                        });


                        above code work best when you used
                        html button in place of input type button
                        Note-- To Show Spin Icon inside Button put
                        font-awesome or any other icon in place of Processing.. or both in loadingText object







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Apr 1 at 7:11

























                        answered Apr 1 at 6:56









                        Haider AliHaider Ali

                        213




                        213













                        • it prevent multiple click (submit) until first click event completed by... disabling button by default ,,

                          – Haider Ali
                          Apr 1 at 7:09



















                        • it prevent multiple click (submit) until first click event completed by... disabling button by default ,,

                          – Haider Ali
                          Apr 1 at 7:09

















                        it prevent multiple click (submit) until first click event completed by... disabling button by default ,,

                        – Haider Ali
                        Apr 1 at 7:09





                        it prevent multiple click (submit) until first click event completed by... disabling button by default ,,

                        – Haider Ali
                        Apr 1 at 7:09











                        1














                        $(document).ready(function() {
                        $(function() {
                        $("#submit_btn").click(function() {
                        $("#submit_btn").attr("disabled", "disabled");
                        this.value = "Processing...";
                        outerthis = this;
                        setTimeout(function() {
                        outerthis.value = "Submit";
                        $("#submit_btn").removeAttr("disabled");
                        }, 5000);
                        });
                        });
                        });





                        share|improve this answer






























                          1














                          $(document).ready(function() {
                          $(function() {
                          $("#submit_btn").click(function() {
                          $("#submit_btn").attr("disabled", "disabled");
                          this.value = "Processing...";
                          outerthis = this;
                          setTimeout(function() {
                          outerthis.value = "Submit";
                          $("#submit_btn").removeAttr("disabled");
                          }, 5000);
                          });
                          });
                          });





                          share|improve this answer




























                            1












                            1








                            1







                            $(document).ready(function() {
                            $(function() {
                            $("#submit_btn").click(function() {
                            $("#submit_btn").attr("disabled", "disabled");
                            this.value = "Processing...";
                            outerthis = this;
                            setTimeout(function() {
                            outerthis.value = "Submit";
                            $("#submit_btn").removeAttr("disabled");
                            }, 5000);
                            });
                            });
                            });





                            share|improve this answer















                            $(document).ready(function() {
                            $(function() {
                            $("#submit_btn").click(function() {
                            $("#submit_btn").attr("disabled", "disabled");
                            this.value = "Processing...";
                            outerthis = this;
                            setTimeout(function() {
                            outerthis.value = "Submit";
                            $("#submit_btn").removeAttr("disabled");
                            }, 5000);
                            });
                            });
                            });






                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Apr 1 at 8:10









                            Arend

                            3,53012137




                            3,53012137










                            answered Apr 1 at 6:28









                            SINGH AAKASHSINGH AAKASH

                            192




                            192























                                0














                                Problem about the wrong usage of this keyword inside setTimeout() has already been explained. However, if you are able to use arrow function expressions (ES6 feature), that won't be a problem:




                                An arrow function expression is a syntactically compact alternative to a regular function expression, although without its own bindings to the this, arguments, super, or new.target keywords.




                                Using this feature, your code can be simplified a little as shown on next example:






                                $("#submit_btn").click(function()
                                {
                                $(this).attr("disabled", "disabled").val("Processing...");

                                setTimeout(
                                () => $(this).val("Submit").removeAttr("disabled"),
                                5000
                                );
                                });

                                <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
                                <input id="submit_btn" type="submit" value="Submit" />








                                share|improve this answer






























                                  0














                                  Problem about the wrong usage of this keyword inside setTimeout() has already been explained. However, if you are able to use arrow function expressions (ES6 feature), that won't be a problem:




                                  An arrow function expression is a syntactically compact alternative to a regular function expression, although without its own bindings to the this, arguments, super, or new.target keywords.




                                  Using this feature, your code can be simplified a little as shown on next example:






                                  $("#submit_btn").click(function()
                                  {
                                  $(this).attr("disabled", "disabled").val("Processing...");

                                  setTimeout(
                                  () => $(this).val("Submit").removeAttr("disabled"),
                                  5000
                                  );
                                  });

                                  <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
                                  <input id="submit_btn" type="submit" value="Submit" />








                                  share|improve this answer




























                                    0












                                    0








                                    0







                                    Problem about the wrong usage of this keyword inside setTimeout() has already been explained. However, if you are able to use arrow function expressions (ES6 feature), that won't be a problem:




                                    An arrow function expression is a syntactically compact alternative to a regular function expression, although without its own bindings to the this, arguments, super, or new.target keywords.




                                    Using this feature, your code can be simplified a little as shown on next example:






                                    $("#submit_btn").click(function()
                                    {
                                    $(this).attr("disabled", "disabled").val("Processing...");

                                    setTimeout(
                                    () => $(this).val("Submit").removeAttr("disabled"),
                                    5000
                                    );
                                    });

                                    <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
                                    <input id="submit_btn" type="submit" value="Submit" />








                                    share|improve this answer















                                    Problem about the wrong usage of this keyword inside setTimeout() has already been explained. However, if you are able to use arrow function expressions (ES6 feature), that won't be a problem:




                                    An arrow function expression is a syntactically compact alternative to a regular function expression, although without its own bindings to the this, arguments, super, or new.target keywords.




                                    Using this feature, your code can be simplified a little as shown on next example:






                                    $("#submit_btn").click(function()
                                    {
                                    $(this).attr("disabled", "disabled").val("Processing...");

                                    setTimeout(
                                    () => $(this).val("Submit").removeAttr("disabled"),
                                    5000
                                    );
                                    });

                                    <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
                                    <input id="submit_btn" type="submit" value="Submit" />








                                    $("#submit_btn").click(function()
                                    {
                                    $(this).attr("disabled", "disabled").val("Processing...");

                                    setTimeout(
                                    () => $(this).val("Submit").removeAttr("disabled"),
                                    5000
                                    );
                                    });

                                    <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
                                    <input id="submit_btn" type="submit" value="Submit" />





                                    $("#submit_btn").click(function()
                                    {
                                    $(this).attr("disabled", "disabled").val("Processing...");

                                    setTimeout(
                                    () => $(this).val("Submit").removeAttr("disabled"),
                                    5000
                                    );
                                    });

                                    <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
                                    <input id="submit_btn" type="submit" value="Submit" />






                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Apr 1 at 18:50

























                                    answered Apr 1 at 18:28









                                    ShiderszShidersz

                                    10.2k2933




                                    10.2k2933






























                                        draft saved

                                        draft discarded




















































                                        Thanks for contributing an answer to Stack Overflow!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid



                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.


                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function () {
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55448780%2fbutton-value-to-be-changed-back-to-original-value-on-timeout-form-double-submit%23new-answer', 'question_page');
                                        }
                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        Popular posts from this blog

                                        "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

                                        Alcedinidae

                                        Origin of the phrase “under your belt”?