3

i have the follow code:

<input class="any" type="text" id="myId" name="myName" />

this input is a jquery datepicker.. (http://jqueryui.com/datepicker/)

My JS is as follows:

$('#myId').keypress(function(evt) {
   //codes
});

I tried keypress, keydown and keyup.. all not working in IE..

May be because of the jquery date picker plugin?

I also tried with jquery hotkey plugin (https://github.com/jeresig/jquery.hotkeys/blob/master/jquery.hotkeys.js)

But, no success :(

i just want to capture the enter event..

Any help?

Felipe

fdam
  • 820
  • 1
  • 11
  • 25
  • And it works in other browsers ? – adeneo Sep 24 '13 at 18:56
  • Strange... Not even keydown working for me on IE10 - http://jsfiddle.net/eNjWQ/ – Rikard Sep 24 '13 at 19:04
  • Which version of IE and which version of jQuery are you trying this with? – Jonathan Lonowski Sep 24 '13 at 19:04
  • Maybe this can help [SO Link](http://stackoverflow.com/questions/302122/jquery-event-keypress-which-key-was-pressed) – FxckDead Sep 24 '13 at 19:05
  • it works fine in chrome and FF, my IE version: 9.0.8112.16421 and jquery version: 1.9.1.. much stranger.. – fdam Sep 24 '13 at 19:09
  • this example not work for me Rikard, But my IE version is 9.0.8112.. and i can't update to 10 :( – fdam Sep 24 '13 at 19:12
  • 1
    It works for me, in Chrome and IE 9. Strangly the fiddle from @Rikard does NOT work for me in IE, but if I create a testfile it does. – Jay Claiton Sep 24 '13 at 19:20
  • if you change jquery version to 1.9.1 it works @JayClaiton, this is stranger, because this is the version of my project.. i will try update to 1.10.1, but i don't know if this update will not break the others components. At least for test. – fdam Sep 24 '13 at 19:31

2 Answers2

0

If the element doesn't exist on the page on the initial load, then the event may not be bound to the button. Not sure why it works in other browsers though.

Could possibly try this to see if it helps

$(document).on('keypress', '#myId', function() {
 // ....
});

if you're using an older version of jQuery, then you'll need to use .live().

Ricky S
  • 371
  • 1
  • 8
  • http://jsfiddle.net/gaUeY/ jquery 1.9.1 on IE 9 works.. but no in my project.. anyway, should be some other problem maybe with others plugins. @RickyS – fdam Sep 24 '13 at 19:43
0

Solved: http://jsfiddle.net/MJWUw/

IE doesn't recognize a keyevent just with click in this input, but if i navigate until the field with tabspace it works.. i did a workaround to solve this, set the focus manually and it's working right now.

$("#myId").click(function(evt){$(this).focus();});

$('#myId').keyup(function(evt) {
   alert('working!')
});

att

fdam
  • 820
  • 1
  • 11
  • 25