+ 1

Why the value doesn't doesn't get cleared?, please help

I want to clear the input after the alert message when someone is trying to paste text in there but the text remains in the input although I did set it to empty after the alert! https://code.sololearn.com/W066tbojMumw/#html

17th Mar 2020, 2:01 AM
Glory222
Glory222 - avatar
3 Réponses
+ 5
setTimeout takes two(or more) arguments. First one is a callback function that will be called after X miliseconds. X is the second argument. setTimeout first waits for all pending tasks. Then waits X milliseconds and calls the callback function. In my code I used setTimeout (function,0) to wait for the paste event fulfillment. This way i cleared the input value 0 milliseconds(a bit more but as soon as js could) AFTER the value was pasted and updated.
17th Mar 2020, 2:26 PM
Kevin ★
+ 3
Because myFunction gets called just before the input value is updated. Solutions: https://code.sololearn.com/Wt6KflNXms6O/?ref=app https://code.sololearn.com/WtLlQbo4GqtU/?ref=app
17th Mar 2020, 2:25 AM
Kevin ★
+ 1
Thank you so much Kevin Star ! The code works perfectly But could you please explain me what on earth is setTimeout doing on here?
17th Mar 2020, 4:33 AM
Glory222
Glory222 - avatar