By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,574 Members | 1,459 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,574 IT Pros & Developers. It's quick & easy.

How can I force a radiobutton to accept focus

P: 110
I have a screen that begins with a radiobutton. For some reason it does not accept focus until the tab key is pressed. I use a js line to assign focus to the radiobutton but the radiobutton does not accept it. All my other pages have focus set on the first object when the page is displayed. What can I do to cause the radiobutton to have focus? Here's the code line I am now using:

Expand|Select|Wrap|Line Numbers
  2. document.getElementById('numberPropertyLosses').focus();
where 'numberPropertyLosses' is the name of the radiobutton set.
Jan 19 '09 #1
Share this Question
Share on Google+
5 Replies

Expert Mod 5K+
P: 5,390
as far as i'm aware it basicly should work ... FF shows you the focus but IE does not? ... you could try to press the space-bar and the radio should be checked ... so it's quite tricky to handle that issue. you may play with setting a border that 'simulates' the focus for IE and drop it onblur or something like that?

kind regards
Jan 19 '09 #2

P: 110
Better yet, is there a way to simulate a tab key press? Pressing the space bar has no effect because the radiobutton does not have focus. Once it does have focus pressing the spacebar does, in fact, select it. But I need to give focus to a radiobutton that is first at the top of a new page.
Jan 19 '09 #3

P: 33
Hmm, I tested this myself, pressing spacebar does check the radio button in IE7, so it just doesn't "appear" to have focus? Chrome showed focus fine.
Jan 19 '09 #4

Expert Mod 15k+
P: 16,027
This is where the problem is. Either use the ID or use:
Expand|Select|Wrap|Line Numbers
  1.  document.getElementsByName('numberPropertyLosses')[0].focus();
Jan 19 '09 #5

Expert Mod 5K+
P: 5,390
ahh ... i overlooked that. but in case the node is selected correctly the above mentioned problem occurs in IE.
Jan 20 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.