-3

I'm attempting to write a very basic script using javascript. What I want to do is be able to detect whenever a textarea is modified, and then make some changes to other elements.

This is my jsfiddle: http://jsfiddle.net/QDRHT/1/

I'm attempting to detect whenever a new character is entered into the textarea, then modify the background color of a nearby div. However, it's not working at all, and I can't tell why (I'm new to Javascript, although I did make sure to validate my HTML and CSS, and run the javascript through JSLint).

If it matters, I'm running this in IE 9.

Michael0x2a
  • 58,192
  • 30
  • 175
  • 224
  • possible duplicate of [Textarea onchange detection](http://stackoverflow.com/questions/2823733/textarea-onchange-detection) – Diodeus - James MacFarlane Jun 29 '12 at 18:46
  • This is actually working fine. Your fiddle is being wrapped by MooTools... `window.addEvent('load', function() { [your code is here] }`. You should be able to see the results if you remove the `window.onload` part – MilkyWayJoe Jun 29 '12 at 18:48
  • Removing only in context of jsfiddle, it should still work fine if he puts that code in his actual page, it works with onload on jsbin though – Blaster Jun 29 '12 at 18:56

2 Answers2

2

Change onKeyPress to onkeypress eg all lower-case characters and should work.

DEMO

Community
  • 1
  • 1
Blaster
  • 9,414
  • 1
  • 29
  • 25
1

The window.onload handler will not be triggered, because you add this within other load event's handler.So remove it. Also instead of onKeyPress use onkeypress(all letters should be lowercase).

Changed version is here.

Engineer
  • 47,849
  • 12
  • 88
  • 91