Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tab order on radio button not correct

Here is an example form I have.

http://jsfiddle.net/r45WL/

<input autocomplete="off"  id="FirstName" name="FirstName" type="text" value="" /><br/>
<input autocomplete="off" id="LastName" name="FirstName" type="text" value="" /><br/>    
<p style="float:left"><input id="YN_true" name="YN" type="radio" value="true" />Yes</p>
<p style="float:left"><input id="YN_false" name="YN" type="radio" value="false" >No</p>
<br/><br/>
<input autocomplete="off" id="CellPhone" maxlength="12" name="CellPhone" type="text" value="" />


$(document).ready(function(){  
  $("#FirstName").attr("tabindex", 1);
    $("#LastName").attr("tabindex", 2);
    $("#YN_true").attr("tabindex", 3);
    $("#YN_false").attr("tabindex", 4);
    $("#CellPhone").attr("tabindex", 5);   

}

The tab order works fine if you tab all the way through, but if you get to the radio buttons, then use the mouse to select an option, it then press tab it will go back to tabindex 1. I need to set tabindex using jquery because I am using MVC3 and I need to use EditorFor.

Is there a way to correct this or is it normal?

NOTE this happens in Chrome, not IE.

Edit: I guess its an existing bug https://code.google.com/p/chromium/issues/detail?id=181144

like image 882
RJP Avatar asked Dec 05 '25 05:12

RJP


1 Answers

I've fixed this by putting $(this).focus(); on my radio buttons.

Like this:

$(document).ready(function(){  
    $("[type=radio]").click(function () {
        $(this).focus();
    });
  $("#FirstName").attr("tabindex", 1);
    $("#LastName").attr("tabindex", 2);
    $("#YN_true").attr("tabindex", 3);
    $("#YN_false").attr("tabindex", 4);
    $("#CellPhone").attr("tabindex", 5);   

}
like image 109
James Avatar answered Dec 07 '25 20:12

James



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!