How to set cursor focus onload?
- by eswaramoorthy-nec
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.