Reputation: 2799
Here is code http://jsfiddle.net/8ZzER/26/
I try to call the function bound to keyup
but keyPres
variable is null
HTML
<input id="text" name="text" type="text" onkeyup="alert('Boom')"
value="Key up here"/>
<input type="button" id="fire" value="fire" />
JavaScript
document.getElementById("fire").onclick=function()
{
var textElement = document.getElementById("fire");
var keyPres= textElement.onkeyup;
keyPres.call();
}
Upvotes: 1
Views: 1864
Reputation: 413757
Your handler is on the element with "id" value "text", but your code looks for "fire".
<input id="text" name="text" type="text" onkeyup="alert('Boom')"
value="Key up here"/>
<input type="button" id="fire" value="fire" />
The handler should look like:
// says "fire" in your jsFiddle
var textElement = document.getElementById("text");
var keyPres= textElement.onkeyup;
keyPres.call();
Upvotes: 3
Reputation: 29160
Well, you are assigning textElement
to your button (fire
) and not your text box.
Upvotes: 1