How to set cursor focus onload?

Posted by eswaramoorthy-nec on Stack Overflow See other posts from Stack Overflow or by eswaramoorthy-nec
Published on 2010-06-17T10:04:10Z Indexed on 2010/06/17 10:23 UTC
Read the original article Hit count: 518

Filed under:
|
|
|
|

Hi,

I use h:selectOneRadio tag.
I need to set the cursor focus to first radio field.

<f:view>
<html>
     <head>
           <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">      
     </head>
     <body>
         <h:form id="focusForm" >
              <h:selectOneRadio id="testRadioId" value="">
                     <f:selectItem id="si1" itemLabel="JSF" />
                     <f:selectItem id="si2" itemLabel="JSP" />
              </h:selectOneRadio>
         </h:form>
</body></html></f:view>

here The Firefox (browser) assign id :focusForm:testRadioId:0 that field.
So i use the following script:

document.getElementById("focusForm:testRadioId:0").focus();

But,
Some times, i may change dynamically disable the radio field from backing bean.

<h:selectOneRadio id="testRadioId" value="">
                 <f:selectItem id="si1" itemLabel="JSF" itemDisabled="true"/>
                 <f:selectItem id="si2" itemLabel="JSP" />
</h:selectOneRadio>

So here i disable the first radio button.
Now, If i use the same script, then not set cursor focus to first radio field.
how to handle this? that means how to alter my script dynamically during onload?

Please help me.
Thanks in advance.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery