• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

Trigger Enter Key Event

 
Ranch Hand
Posts: 2113
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is jqGrid callback function.
The focus part works but the keyup function never fires.

 
Ranch Hand
Posts: 47
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd guess that e.which is undefined. Can you check that?

Also where does $.Event(...) com from?
 
Sheriff
Posts: 67525
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wrote a small test case with code similar to yours and the established event handler triggers just fine.

Your code does not show how you are establishing the keypress handler; how are you doing that?

And... why the timeout?
 
Bear Bibeault
Sheriff
Posts: 67525
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Christian Wansart wrote:I'd guess that e.which is undefined. Can you check that?


which is a standard property of the Event construct.

Also where does $.Event(...) com from?


jQuery
 
Bear Bibeault
Sheriff
Posts: 67525
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And, what is it you are expecting this line to do?
 
Steve Dyke
Ranch Hand
Posts: 2113
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:

Your code does not show how you are establishing the keypress handler; how are you doing that?

And... why the timeout?



This is code I found on internet. I am not sure about establishing the keypress handler.

This is from jQuery Docs:
The jQuery.Event constructor is exposed and can be used when calling trigger. The new operator is optional.

I have found that some of my javascript functions will not fire without a timeout wrapper.
I have read several posts in my searches this is an issue for others also.
 
Steve Dyke
Ranch Hand
Posts: 2113
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:And, what is it you are expecting this line to do?



Set focus to the input element, which has the value to act upon, before simulating the Enter key press.
 
Bear Bibeault
Sheriff
Posts: 67525
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Steve Dyke wrote:Set focus to the input element, which has the value to act upon, before simulating the Enter key press.



That's what I suspected. But, in fact, it doesn't.

You are calling the jQuery focus method which triggers the focus event handler, if any.

To call the element's focus method, which is what will actually pass focus to that element, you need to extract the element from the jQuery wrapped set, and then call its focus method. As such:
 
Bear Bibeault
Sheriff
Posts: 67525
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Steve Dyke wrote:This is code I found on internet. I am not sure about establishing the keypress handler.



If you do not have a keypress handler, what's the point of trying to trigger it?

I have found that some of my javascript functions will not fire without a timeout wrapper.


Remove the timeout, it's not necessary.

If you have a race condition, perhaps you are not waiting until the DOM has been built to run your code? (Using the hand-dandy jQuery function to run code after the DOM has been loaded, of course.)
 
Bear Bibeault
Sheriff
Posts: 67525
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For reference, here's my test code. (Note: ES6+ syntax, convert to ES5 if targeting legacy browsers -- or not using a Babel toolchain).
 
Destroy anything that stands in your way. Except this tiny ad:
ScroogeXHTML - a fast and small RTF to HTML5 and XHTML converter library
https://coderanch.com/t/742149/ScroogeXHTML-RTF-HTML-XHTML-converter
reply
    Bookmark Topic Watch Topic
  • New Topic