HighDots Forums  

Setting focus on radio button

Javascript JavaScript language (comp.lang.javascript)


Discuss Setting focus on radio button in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Terry Murray
 
Posts: n/a

Default Setting focus on radio button - 09-25-2003 , 11:17 AM






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



Reply With Quote
  #2  
Old   
kaeli
 
Posts: n/a

Default Re: Setting focus on radio button - 09-25-2003 , 12:35 PM






In article <nyEcb.120617$DZ.21199 (AT) news04 (DOT) bloor.is.net.cable.rogers.com>,
tgmurray (AT) rogers (DOT) com enlightened us with...
Quote:
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
-------------------------------------------------


Reply With Quote
  #3  
Old   
Terry Murray
 
Posts: n/a

Default Re: Setting focus on radio button - 09-25-2003 , 01:15 PM



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" <infinite.possibilities (AT) NOSPAMatt (DOT) net> wrote

Quote:
In article <nyEcb.120617$DZ.21199 (AT) news04 (DOT) bloor.is.net.cable.rogers.com>,
tgmurray (AT) rogers (DOT) 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
-------------------------------------------------



Reply With Quote
  #4  
Old   
kaeli
 
Posts: n/a

Default Re: Setting focus on radio button - 09-25-2003 , 02:43 PM



In article <vhGcb.122274$DZ.59829 (AT) news04 (DOT) bloor.is.net.cable.rogers.com>,
tgmurray (AT) rogers (DOT) com enlightened us with...
Quote:
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
-------------------------------------------------


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.