开发者

Why onchange doesn't work?

I'm just looking for an answer on the net but I haven't reached any one. I'm playing with google's api translation and I have a problem with JS. In fact my code is 100% ok except one operation.

My problem is that the translation is not given at the time. After js sends the information to google it doesn't wait until the translation is given. Instead of this it continues reading my code so it doesn't stop for get an answer. It proceess the information to be translated and then the answer will be get some time after. So because I want to do translations of translations I have done a sweet loop. Because I don't know how to stop js, I have done a page with diferent inputs text box and in my loop when the data is received it's send to the value of the text box and here is where it becomes the problem. I want to enter to my js function again when the tex开发者_运维技巧t is changed so If js changes the value it will return to my loop when I get the translation. Simply and effective but if I put in the input box:

onchange="myfunction()"

the loop doesn't work. But the strangest is that if I manually change the text then the function works so it's as if onchange only works when a human change the text but not if js change the text. Is there any solution? May be some dinamic listener or something like that?


The onchange event only fires if the user changes the value of the input. It isn't supposed to fire if the input is changed programmaticly.

Call the function from whatever function sets the value instead.


The onchange event is designed to fire when the user (and only the user) changes the value and for that reason it is fired only after the value was changed AND field lost focus.


Helpful Starters and that Bucle you speak of


  1. You should look at the onkeyup or onblur.
  2. If the input value is being set by JavaScript, then why not call the event after setting it?

I have no idea what a bucle is.
My best guess: it is Spanish for 'loop'

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜