• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Putting focus on Jquery wodal window

 
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Everyone,

Needed one help regarding putting focus on a modal window. When my parent JSP loads, the modal window loads on top of that but it does not have focus on it. The modal window has two buttons Cancel and Submit and close link to close the window. On clicking them I do an AJAX submit to a struts 2.0 class. Also I wanted to include the Escape key to behave the same way as the cancel button. But somehow the modal window does not have focus, hence the escape key does not register. Only when I click somewhere on the modal, the escape key works. I have done the coding for it.. just needed to know how to make the modal work.


The checkEsc(e) method contains the logic for handling the escape.
 
Somnath Mallick
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also tried doing onload="self.focus();" on the body tag of the modal but did not work.
 
Sheriff
Posts: 67746
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
"colorbox" is not part of core jQuery -- so I'm assuming it's a plugin that you found. It'd likely be best to consult the plugin's documentation to see if it has hooks for this.
 
Author
Posts: 38
jQuery
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you adding a window.load callback within the document.ready one? The former should be unnecessary.

At the moment you are adding a document.keypress handler every time the window.keypress event is triggered. As above, you should probably remove the window.keypress handler and just keep the other one.
 
Bear Bibeault
Sheriff
Posts: 67746
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
Cool! Keith is hanging around after the promo!
 
Somnath Mallick
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry i went missing. Thanks Keith for the tip.

@Bear: I tried looking up colorbox for some hooks but did not find anything. Is there any other way of doing it?
 
Bear Bibeault
Sheriff
Posts: 67746
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
What exactly do you want to give focus to? I suppose you could use the browser debugger to dig around the DOM created by the plugin and find an element that you cab give focus to. Or maybe find a better plugin.
 
Somnath Mallick
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I googled up and found that using a hidden text box and giving focus to it is a good way of doing it. Just was wondering that is there any other way of doing it.
 
Bear Bibeault
Sheriff
Posts: 67746
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
As I already said, give the focus to an already existing element. You can use the browser's debugger to look at the DOM.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic