Why does onchange not work?

I'm just looking for an answer online, but I have not reached anyone. I play with google api translation and I have problem with JS. Actually my code is 100% normal except for one operation.

My problem is that the translation is not given at that time. After js sends the information to google, it does not wait for the transfer. Instead, he continues to read my code, so he does not stop to get a response. It processes the information that will be translated, and then a response will be received some time after. Therefore, since I want to do translations of translations, I made a sweet loop. Since I don’t know how to stop js, I made a page with a different input text field, and in my loop, when the data is received, they send the value of the text field, and this is where it becomes the problem. I want to enter my js function again when the text is changed. If js changes the value, it will return to my loop when I receive the translation. Simple and effective, but if I put in the input field:

onchange="myfunction()"

the loop is not working. But the strangest thing is that if I manually change the text, the function works as if onchange only works when a person changes the text, but does not change the js text. Is there a solution? Maybe some kind of dynamic listener or something like that?

+3
source share
3 answers

The event is onchangetriggered only if the user changes the value of the input. It should not fire if the input is changed programmatically.

Call a function from any function that sets a value instead.

+6
source

onchange , ( ) , , , .

+2

Useful starters and what Bucle you say


  • You should look at onkeyupor onblur.
  • If the input value is set by JavaScript, then why not trigger the event after setting it?

I have no idea what a bunch is.
My best guess: this is spanish for 'loop'

+1
source

Source: https://habr.com/ru/post/1766090/


All Articles