How can I force a radiobutton to accept focus

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • andersond
    New Member
    • Feb 2007
    • 110

    How can I force a radiobutton to accept focus

    I have a screen that begins with a radiobutton. For some reason it does not accept focus until the tab key is pressed. I use a js line to assign focus to the radiobutton but the radiobutton does not accept it. All my other pages have focus set on the first object when the page is displayed. What can I do to cause the radiobutton to have focus? Here's the code line I am now using:

    Code:
     
    document.getElementById('numberPropertyLosses').focus();
    where 'numberProperty Losses' is the name of the radiobutton set.
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    as far as i'm aware it basicly should work ... FF shows you the focus but IE does not? ... you could try to press the space-bar and the radio should be checked ... so it's quite tricky to handle that issue. you may play with setting a border that 'simulates' the focus for IE and drop it onblur or something like that?

    kind regards

    Comment

    • andersond
      New Member
      • Feb 2007
      • 110

      #3
      Better yet, is there a way to simulate a tab key press? Pressing the space bar has no effect because the radiobutton does not have focus. Once it does have focus pressing the spacebar does, in fact, select it. But I need to give focus to a radiobutton that is first at the top of a new page.

      Comment

      • flydev
        New Member
        • Feb 2008
        • 33

        #4
        Hmm, I tested this myself, pressing spacebar does check the radio button in IE7, so it just doesn't "appear" to have focus? Chrome showed focus fine.

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Originally posted by andersond
          Code:
           
          document.getElementById('numberPropertyLosses').focus();
          where 'numberProperty Losses' is the name of the radiobutton set.
          This is where the problem is. Either use the ID or use:
          Code:
           document.getElementsByName('numberPropertyLosses')[0].focus();

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5390

            #6
            ahh ... i overlooked that. but in case the node is selected correctly the above mentioned problem occurs in IE.

            Comment

            Working...