Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using .onKeyUp and .onChange with Javascript DOM objects

I'm having a weird problem with some JavaScript/DOM code I've been playing with. I'm trying to assign the .onKeyUp and .onChange events/methods to a text input like so:

form.elements["article"].onkeyup = "alert('test');";

Oddly, assigning using that method is doing nothing, and I'm forced to do this manually using:

form.elements["article"].setAttribute("onkeyup", "alert('test');");

Am I missing something here? I've used the first method I mentioned before and it has worked fine.

like image 797
bloudermilk Avatar asked May 25 '26 23:05

bloudermilk


1 Answers

Try this:

form.elements["article"].onkeyup = function() { alert("test"); };

Steve

like image 57
Steve Harrison Avatar answered May 27 '26 11:05

Steve Harrison



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!