1

I'm trying to get the onkeydown property to run a JS function that just has an alert, it works on Chrome and FF but not in IE9. Neither keydown, keyup nor keypressed work on IE9. This is the code I used for testing:

JS:

function method()
{
   alert("hi");
}

ASP:

<asp:TextBox id ="tb" runat = "server" onkeydown = "method();"/>

I tried calling it like this onkeydown = "method();" and like this onkeydown = "method(); return false;" and neither worked.

By the way, on the program I'm planning to implement this, the textBox has an extender. Regular HTML won't work here ^_^'

Also, I can't post too much of the original source due to clients request to keep it closed source.

Any suggestion would be greatly appreciated.

3 Answers3

1

I wrote the code and i just need to change the method name to work.

I was using onkeydown="method()" but when i change to onkeydown="methodXX()" the magic works. And of course i change JavaScript code.

Daniel Moreira
  • 430
  • 4
  • 17
  • This. It could very well be related to the [`method` property](https://msdn.microsoft.com/en-us/library/ie/ms534167.aspx) exposed by Internet Explorer. Although it's supposed to only be applicable to `
    ` elements and not to be global. Then again, that's IE, so who knows.
    – Frédéric Hamidi Apr 27 '15 at 13:40
  • 1
    My function's name, on test environment, is BBQ and still wasn't working. Didn't post it like that cause it's silly and I was pretty sure it won't change – José Corretjer-Gómez Apr 27 '15 at 13:55
  • 1
    Can you share a fiddle with us? – Daniel Moreira Apr 27 '15 at 13:58
  • My test is pretty much what I posted here but with BBQ as function name and Monkey as textBox id. I don't think it's necessary to show the code of the program I want to use it in cause I already figure what to do when it's called. Also, its quite long and my client prefers to be closed source – José Corretjer-Gómez Apr 27 '15 at 14:11
  • In theory, if it works with this test it should work on my program cause all I need is to call the function from that control. But if you REALLY need it to formulate a suggestion, I'll see what I can do. – José Corretjer-Gómez Apr 27 '15 at 14:17
  • 1
    @FrédéricHamidi I, sometimes, think MS projects start off being designed by humans and implemented by donkeys – José Corretjer-Gómez Apr 27 '15 at 14:21
0

Try this.

Code would look like this,

<input id ="tb" runat = "server" onkeydown = "method();"/>
TGarrett
  • 562
  • 4
  • 15
  • I need the event to be fired when a key is pressed not on clicks, but thanks for suggesting – José Corretjer-Gómez Apr 27 '15 at 13:25
  • 1
    My apologies, I misread the question. In his case, I would open up F12 developer tools to analyse what is going on. I have always had issues with the samething, I just noticed he is using asp.net textbox control instead of an input control, I would advise changing to a input control and adding runat="server in the tag, this will have the same results as above and will work :) – TGarrett Apr 27 '15 at 13:27
  • It would've work, but the control I'm aiming for, in the original program, it has en extender tied to it. But it's a great suggestion – José Corretjer-Gómez Apr 27 '15 at 13:51
  • You never said that in your original question, I would stay away from extenders, they are an ugly way to do stuff. – TGarrett Apr 27 '15 at 13:57
  • Yeah, they can be annoying, but some can be pretty useful. – José Corretjer-Gómez Apr 27 '15 at 14:13
0

I changed my approach from OnKeyDown to OnMouseMove to simulate a threaded loop. Called it on a div that enclosures the whole page. This div doesn't do anything, it's purpose is to call the OnMouseMove function, that way I can do the same thing I wanted to do with the OnKeyDown. Thanks for the support!