aspose file tools
The moose likes HTML, CSS and JavaScript and the fly likes Set focus to a label field Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "Set focus to a label field" Watch "Set focus to a label field" New topic
Author

Set focus to a label field

Swapna Agde
Greenhorn

Joined: Mar 29, 2010
Posts: 6
Hi,
I want to set focus to a label field in HTML using javascript.

On buttonclick I am setting the focus to the label:

However, the focus is not set to the 'label'. Instead it remains on the button.
Please help.
Devaka Cooray
Saloon Keeper

Joined: Jul 29, 2008
Posts: 2729
    
    3

"swap aj", have you red the private message which was sent to you by Bear yesterday?


Author of ExamLab (Download) - the free mock exam kit for SCJP / OCPJP
HELP me! -- Home Page -- Twitter Profile -- JavaRanch FAQ -- How to Ask a Question
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15362
    
    6
Labels should be linked to a form element and when they are normally focused, they focus the element they are linked too. Don't you have a for="blahId" on it?

Eric
Swapna Agde
Greenhorn

Joined: Mar 29, 2010
Posts: 6
Not clear with the last part i.e "for="blahId""?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15362
    
    6
Swapna Agde wrote:Not clear with the last part i.e "for="blahId""?


The spec document: http://www.w3.org/TR/html401/interact/forms.html#h-17.9.1

I wonder if onfocus does not fire when JavaScript sets it.

Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Set focus to a label field
 
Similar Threads
I keep getting on Javascript Error on the bottom left of IE
Copying Components
Multiple actions on timers anyone?
Help with Timers!
How to stop page refresh when hit enter button from rich:inputNumberSpinner field?