This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Putting focus on Jquery wodal window Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Putting focus on Jquery wodal window" Watch "Putting focus on Jquery wodal window" New topic
Author

Putting focus on Jquery wodal window

Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 477
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

Joined: Mar 04, 2009
Posts: 477
I also tried doing onload="self.focus();" on the body tag of the modal but did not work.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61451
    
  67

"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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Keith Wood
Author
Ranch Hand

Joined: Aug 28, 2012
Posts: 38

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.


Author of the upcoming "Extending jQuery" book from Manning.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61451
    
  67

Cool! Keith is hanging around after the promo!
Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 477
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61451
    
  67

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

Joined: Mar 04, 2009
Posts: 477
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61451
    
  67

As I already said, give the focus to an already existing element. You can use the browser's debugger to look at the DOM.
 
wood burning stoves
 
subject: Putting focus on Jquery wodal window