Setting focus on radio button

T

Terry Murray

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
 
K

kaeli

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
-------------------------------------------------
 
T

Terry Murray

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 said:
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
-------------------------------------------------
 
K

kaeli

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top