How to focus radio control using Javascript in IE?

Go To StackoverFlow.com

0

Given the code below:

function test() {
    document.forms[0].TEST[0].focus();
}
    <form>
        <input type="button" value="Test" onclick="test()" />
        <input type="radio" name="TEST" value="A">A</input>
        <input type="radio" name="TEST" value="B">B</input>
    </form>

In IE6, clicking the button doesn't focus the control, unless I've already tabbed through the radio at least once, in which case it works. =/

Any idea how I should be focusing the control? The above works perfectly fine in FF of course.

Edit: I found that the control is being focused, except the highlight box around the radio button is not being rendered. (I can hit space to activate the radio button, and also use arrow keys to change the active button). So the question becomes: how can I force the focus highlighting box to render?

2009-06-16 07:38
by Roy Tang
WFM - have you tried this on other instances of IE - annakata 2009-06-16 07:59
Do you want to "click" it or just focus - Sorin Comanescu 2009-06-16 08:50
notice your input tags are not proper marku - arhak 2016-10-27 09:28


0

Actually it's focussing, you can test it by focusing the second item and after clicking the button click space, you can see the second item selected. This shows the items are getting focus but I think you mean the dashed selection after focus. I don't know how to do that.

2009-06-16 07:41
by Canavar
Um...that doesn't work either. It doesn't seem to matter how I got the relevant radio element (whether by id or referencing through the form). The problem seems to be with the focus() function of IE itself - Roy Tang 2009-06-16 07:48


0

There's an option in the Accessibility Advanced Options of Internet Explorer that says something like "Move the system cursor with selection or focus". It might be a solution if you have a way to propagate IE settings.

edit: it doesn't work

2009-06-16 08:16
by Alsciende
No, it doesn't, unless there's a way to manipulate IE settings with Javascript - TFM 2009-06-16 08:32
There may be. Regardless, in some projects, you can enforce internet explorer settings - Alsciende 2009-06-16 08:36
Well, rather than leaving the rest of us in the dark, maybe you have an example code to share with us - TFM 2009-06-16 08:40
Hum no. I said that there "may be" a way to set ie options by javascript, because I think it's possible to do the same thing in firefox. But what I meant is that if it's an intranet project, Roy Tang may be able to give his users directions on how to properly configure IE. That's what we do with our project, actually: we configure IE for our clients, and this is one of the options that we set - Alsciende 2009-06-16 08:46
well, it doesn't work - Alsciende 2009-06-16 08:51
After the edit, my answers look a bit off topic. :p

Well, there cannot be a way to manipulate browser settings with Javascript, it would be a MAJOR security mistake - TFM 2009-06-16 08:54

That's perfectly true. But Firefox has user.js that lets users change their settings by javascript, kinda : - Alsciende 2009-06-16 09:55


0

You can force any style for the focus' outline

function test() {
    document.forms[0].TEST[0].focus();
}
/* if this CSS rule is overrode by another one, then strengthen the selector of this rule to make it more specific (or use "!important") */
input[name=TEST]:focus {
    outline: 1px dotted blue;
}
<form>
    <input type="button" value="Test" onclick="test()" />
    <input type="radio" name="TEST" value="A" />
    <input type="radio" name="TEST" value="B" />
</form>

2016-10-27 09:26
by arhak
Ads