0

I want any time my submit value changed to Thanks do something for me, my submit id is #pollsubmit

So i tried to solve the problem with setTimeout( function()

But i think this is not a good solution and there may be a better solution to this problem

$("#pollsubmit").on("click", function() {
  setTimeout( function() { 
    if($("#pollsubmit").val() == 'Thanks'){
      // Do Something
    }else{
        setTimeout( function() { 
           if($("#pollsubmit").val() == 'Thanks'){
            // Do Something
            }else{
              setTimeout( function() { 
                 if($("#pollsubmit").val() == 'Thanks'){
                   // Do Something
                 }else{
                 }
              },1500);
            }
        },1500);
       }
  },1500);
});

The problem is, i do not know how many seconds it takes to change the value of a submit to Thanks


before ask this question i read this topic but my question is different, because the value of my button after clicking first changes to Loading and then to Thanks, in fact i need a timer to check frequently, after change value,

ex:

Button value is Submit after Click

First: Value changed to Loading

Second: Value changed to Thanks


Can anyone help me with this?

Thanks for any help

alam7o
  • 61
  • 8
  • 2
    Does this answer your question? [Detecting input change in jQuery?](https://stackoverflow.com/questions/6458840/detecting-input-change-in-jquery) – Alexandre Elshobokshy Aug 15 '20 at 11:28
  • Who is "#pollsubmit"? – Arthur Rubens Aug 15 '20 at 11:31
  • 2
    @alam7o This question seems to be an [XY problem](https://en.wikipedia.org/wiki/XY_problem), and while it could be "solved" with an interval, there is still information missing which could potentially make the answer considerably simpler, like what is causing the input's value to change in the first place. – Daedalus Aug 15 '20 at 11:43
  • 1
    Better would be to add a change event listener to the **button** and trigger a change event whenever you are changing the value of the **button**. Refer here: https://stackoverflow.com/questions/28360149/how-to-detect-button-value-change-in-jquery – Kunal Kukreja Aug 15 '20 at 11:55
  • @IslamElshobokshy in fact before ask this question check [this](https://stackoverflow.com/questions/6458840/detecting-input-change-in-jquery) topic, but not helping me – alam7o Aug 15 '20 at 12:23
  • @ArthurRubens `#pollsubmit` is id of submit button for my form – alam7o Aug 15 '20 at 12:24

1 Answers1

2

You could activate a timer and check frequently, after the change cancel it

 $("#pollsubmit").on("click", function() {
      const id = setInterval(() => {
        if ($("#pollsubmit").val() == 'Thanks') {
          clearInterval(id)
          //Do Something
        }
      }, 100);
    });
EugenSunic
  • 13,162
  • 13
  • 64
  • 86