开发者

Input element's value changed: do something

As the title of my question states. whenever the value of an input element changes I want it to execute a function. I know that the function is working because I've been tested in onkey events like onkeyup. But, I don't wont to use onkey events because I have scripts that manipulate the input element's value.开发者_如何学JAVA I also know that the problem lies in the first argument of the addEventListener method. I've tred various arguments like DOMAttrModified/change/DOMsomethingelse but it doesn't work. I've also looked at some similiar questions here in SO, JS Events: hooking on value change event on text inputs. The below code works for onkey events:

inputTitle.addEventListener('DOMAttrModified',function(event){
        someFunction(this.value);
},false);

Can someone pls help me. I Have tried to solve this problem for a long time now without success and I know that this is just a small one too. Pls give me some code example that is tested and working.

UPDATE: I've been wrong about one thing above. If I use the "change" event the function will be executed after it looses focus on the input element. So it does work. But I want it to work like onkeyup event, where the function is executed in realtime like Google instant. Unfortunenately, I can't use 'keyup' event beacuse I have som scripts that or say a button that are modifying the input element's value. When these scripts are run, the function is not executed.

UPDATE2: I figured out a work around this problem. And it is to add additional scripts to valemodifyings scripts that executes the "someFunction". I don't really like this solution, because it is not nice coding. I have maybe four scripts to calls that function


Try this:

inputTitle.addEventListener("change", function(){});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜