Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Oct 2002
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation focus on a RadioButton

    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();
    }

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    523
    Thanks
    26
    Thanked 0 Times in 0 Posts
    document.all.buttonname.focus() ?

    or is it buttonidname - one of the two..
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

  • #3
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!

    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #4
    Regular Coder
    Join Date
    Sep 2002
    Location
    Louisiana
    Posts
    576
    Thanks
    0
    Thanked 0 Times in 0 Posts
    correct me if I am wrong but can't you do somehting like this

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

  • #5
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #6
    Regular Coder
    Join Date
    Sep 2002
    Location
    Louisiana
    Posts
    576
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yup you can do that or yup I am wrong

  • #7
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yup you can do that. In fact, I prefer that to enacting the click() method that many people use, which is less universal.
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #8
    New Coder
    Join Date
    Oct 2002
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #9
    New Coder
    Join Date
    Jul 2005
    Location
    GMT +7
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by beetle
    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!

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

  • #10
    Regular Coder
    Join Date
    Sep 2005
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Actually, it does work:
    Code:
    <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! )
    Last edited by Pyth007; 01-03-2006 at 03:39 PM.
    If you want answers, write a smart question.

    Yes, someone probably does know how...

    Oh, and if you want to learn, STFW!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •