Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

focusing on a radio button

Status
Not open for further replies.

stemitch2000

Programmer
Nov 12, 2003
47
0
0
GB
Hi, I have a basic form, with some field as radio buttons. How do I give focus to a radio button once the user has pressed submit and the radio button is not checked (i.e. the user has not agreed with the terms and conditions).

thank you
Steven
 
I've always used:

document.forms[FormName].elements[FormField].focus();

to set focus on any form element.
Hope it works for you.

Travis Hawkins
BeachBum Software
travis@cfm2asp.com
 
An example, where FormName is the name of the form and RadioButton is the name of the radio button:
Code:
document.FormName.RadioButton[0].checked

------------------------------------------------------------------------------------------------------------------------
"The major difference between a thing that might go wrong and a thing that cannot possibly go wrong is that when a thing that cannot possibly go wrong goes wrong it usually turns out to be impossible to get at or repair."
--Dou
 
Sorry, to correct:
Code:
document.FormName.RadioButton[0].checked

Though tlhawkins beat me to it... :)

------------------------------------------------------------------------------------------------------------------------
"The major difference between a thing that might go wrong and a thing that cannot possibly go wrong is that when a thing that cannot possibly go wrong goes wrong it usually turns out to be impossible to get at or repair."
--Dou
 
Grrrr... [flame] (I know you already have the answer, but want to actually at least pretend I know what I'm doing today.) The really corrected version, as previously demonstrated by tlhawkins:
Code:
document.FormName.RadioButton[0].focus()

------------------------------------------------------------------------------------------------------------------------
"The major difference between a thing that might go wrong and a thing that cannot possibly go wrong is that when a thing that cannot possibly go wrong goes wrong it usually turns out to be impossible to get at or repair."
--Dou
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top