PDA

View Full Version : focus on a RadioButton


tufanocak
10-03-2002, 01:15 PM
i want to make a focus to Radiobutton, is it possible ?
Or a check of RadioButton when i call check() fonction.

i have write this code on my page,but it seems that focus()
dont work on a Radiobutton,it works on text field etc.

Can i make a check on Radiobutton when i call the check()
fonction.

function check() {

document.form.adresdort.Focus();
// document.form.radiobutton.focus();
// document.forms[o].elements[o].focus();
}

babelfish
10-03-2002, 02:22 PM
document.all.buttonname.focus() ?

or is it buttonidname - one of the two..

beetle
10-03-2002, 10:29 PM
You have to choose one of the radio buttons to focus on, usually the first

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

Remember, radio buttons are arrays!

:D

chrismiceli
10-03-2002, 10:44 PM
correct me if I am wrong but can't you do somehting like this

document.forms[0].radioname[0].checked = true

beetle
10-03-2002, 10:55 PM
Originally posted by chrismiceli
correct me if I am wrong but can't you do somehting like this

document.forms[0].radioname[0].checked = true Yup!

chrismiceli
10-03-2002, 11:56 PM
yup you can do that or yup I am wrong

beetle
10-04-2002, 12:14 AM
Yup you can do that. In fact, I prefer that to enacting the click() method that many people use, which is less universal.

tufanocak
10-04-2002, 07:25 AM
hi chrismiceli

document.forms[0].radioname[0].checked = true

works, Thanks.

i am not sure, but we can not focus on a radiobutton,but we can give them a true value to be checked.

neuron
12-31-2005, 10:00 AM
You have to choose one of the radio buttons to focus on, usually the first

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

Remember, radio buttons are arrays!

:D

It doesn't work. Is there any other way to focus on a radio button? :confused:

Pyth007
01-03-2006, 01:04 PM
Actually, it does work:
<HTML><HEAD>
<TITLE>Radio Button Focus Example</TITLE>
<SCRIPT>
function changeFocus()
{
document.myForm.fruit[0].focus();
// document.myForm.fruit[0].checked=true;
}
</SCRIPT>
</STYLE>
</HEAD>
<BODY>
<form name="myForm">
My radio buttons:<br />
<input type="radio" name="fruit" />Apple<br />
<input type="radio" name="fruit" />Bananna<br />
<input type="radio" name="fruit" />Cherry<br />
<br />
Junky Textbox: <input type="text" name="junky" /><br />
<input type="button" value=" Give Fruit Focus " onclick="changeFocus();" />
</form>
</BODY>
</HTML>
If you run this script, pressing the "Give Fruit Focus" button (which, by the way, will temporarily give the button focus) will give focus to the first radio-button (eg "Apple").

The problem you may be having is that not all browsers do an adequate job of visually displaying when a radiobutton has focus. For example, if you run the above in IE and press the button, it appears that nothing happens; however, you can verify that "Apple" has focus by 1) pressing the spacebar to select the radio-button, 2) hit [tab] to give focus to the next element (the "junky" textbox), or 3) hitting down-arrow to give focus (and selecting) the "Bananna" radio-button.

Other browsers like FF will actually put a square around the button in order to alert the user that the button has focus (hense the above example is more obvious when run with FF).

You may also want to "check" one of the buttons in addition to giving it focus in order to ensure the user knows that the radiobutton has received focus. In the above example, just uncomment the one line inside the function to see this...

(edit: BTW neuron: Thanks for searching first! :) )