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

Setting focus on radio button

P: n/a
Hi All:

I would like to know how to set the focus on a radio button (if it is
possible)

I tried button[0].focus() but with no luck

The reason that I need to do this is to validate a form. If the user does
not select a radio button I would like my validation code to set the focus
at the first radio button within the pair that was not selected that way
he/she does not have to look for it.

Thanks in advance
Terry
Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
In article <ny*******************@news04.bloor.is.net.cable.r ogers.com>,
tg******@rogers.com enlightened us with...
Hi All:

I would like to know how to set the focus on a radio button (if it is
possible)

I tried button[0].focus() but with no luck


document.formname.elements["radioname"][index].focus();

Radios are an array because they all have the same name.
The index goes from 0-(length -1).

-------------------------------------------------
~kaeli~
All I ask for is the chance to prove that money
cannot make me happy.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
Jul 20 '05 #2

P: n/a
Thanks kaeli it seemed to work. Although the focus was only brought close
to the button. Actually the button did not really receive the focus.
Instead what happened was that the form was scrolled to an area that
contained the radio button.

Terry

"kaeli" <in********************@NOSPAMatt.net> wrote in message
news:MP************************@nntp.lucent.com...
In article <ny*******************@news04.bloor.is.net.cable.r ogers.com>,
tg******@rogers.com enlightened us with...
Hi All:

I would like to know how to set the focus on a radio button (if it is
possible)

I tried button[0].focus() but with no luck


document.formname.elements["radioname"][index].focus();

Radios are an array because they all have the same name.
The index goes from 0-(length -1).

-------------------------------------------------
~kaeli~
All I ask for is the chance to prove that money
cannot make me happy.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------

Jul 20 '05 #3

P: n/a
In article <vh*******************@news04.bloor.is.net.cable.r ogers.com>,
tg******@rogers.com enlightened us with...
Thanks kaeli it seemed to work. Although the focus was only brought close
to the button. Actually the button did not really receive the focus.
Instead what happened was that the form was scrolled to an area that
contained the radio button.


That is the expected behavior from what I understand. Otherwise, it
would be a click and would select it. Instead, it focuses on the radio
group (object) containing that element.

If someone knows otherwise, please correct me.

-------------------------------------------------
~kaeli~
All I ask for is the chance to prove that money
cannot make me happy.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.