0

I'm puzzled on why this simple bit of code does not work. So to speak, dash() should be called everytime there has been a keychange. However, I'm getting a bunch of reference errors. I'm doing something wrong and I don't know what.

<input type="text" class="auto" onkeypress="return dash(this)" width="200px">

function dash(e) {
     alert(e);
}

Essentially I'm trying to grab the text from the text box, then evaluate it, then change the value of the textbox after.

http://jsfiddle.net/Q8gyY/

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
GivenPie
  • 1,451
  • 9
  • 36
  • 57
  • You have configured your fiddle in "onLoad" mode, so your `dash()` function resides in the scope of a `load` event handler, not in the global scope. Switch to "No wrap - in body" to fix your problem. – Frédéric Hamidi Jun 03 '14 at 15:10
  • @FrédéricHamidi How will this affect the code in prod? Do I need to put it in the body this way? – GivenPie Jun 03 '14 at 15:12
  • 1
    In production you won't hopefully use inline event handlers. – JJJ Jun 03 '14 at 16:04

0 Answers0