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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can you set focus to a radio button or check box

Status
Not open for further replies.

cinnamoneast

Programmer
Oct 8, 2002
5
US
I am doing a validation script and want to set focus on my radio buttons after I force the validation. Is that possible? Am I right to assume that you can only use the focus() method on text boxes? Thanks
 
You can set the focus to radio buttons and check boxes - but it's hard to tell that it happened. Just set the focus to the radio button element that you want:

document.form.radiobutton[0].focus();

or to the check box:

document.form.checkboxname.focus(); There's always a better way...
 
focus() method is applicable to these objects only:

1. fileUploadName.focus()
2. passwordName.focus()
3. selectName.focus()
4. textName.focus()
5. textareaName.focus()
6. frameReference.focus()
7. windowReference.focus()

As you see, no checkbox or radio are there.

Use "checked" property instead:

checkboxName.checked;
radioName[index].checked;

(Remember that "checked" is not a method but a property, so don't put "()" after it)

However, you can use checkboxName.focus() in Mozilla, but I don't see much sense in this.
 
starway...

In IE5, nn4+, N6 & N7 you can set the focus() for checboxes & radio buttons. (I haven't tried it in IE6)

For radio buttons, you have to supply the element for the button group, ie; button[0].focus(), button[1].focus() etc. Set the focus on checkboxes just like you would for any text input field.

(I have used both of these methods on the last 2 sites I built.)

If the button/checkbox is in the same screen viewing area as the submit button, then you probably won't see the focus change. But with either of these outside the immediate screen view and the focus() will move the page as you would expect. There's always a better way...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top