3 Replies Latest reply on Jun 18, 2010 6:06 AM by Eswara MoorthyNEC

    How to set cursor focus to <h:selectOneRadio> during onload?

    Eswara MoorthyNEC Newbie

      Hi,

       

           I need to set cursor focus to radio button during the page loading.

       

       

      <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>
      

       

      I use firebug. The first item id is :  focusForm:testRadioId:0.

      So i wrote script

       

       

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

       

      I think this is hard code.

      Is any otherway to set focus to the radio field.

      Help me about this.

      Thanks in advance.

       


        • 2. Re: How to set cursor focus to <h:selectOneRadio> during onload?
          Eswara MoorthyNEC Newbie

          Hi,

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


           

          Suppose, i set the itemDisabled attribute is dynamically changed or false .

           

          This time not set cursor focus to first radio filed, when i use the following script.

           

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

           

          Because the first radio field is disabled.

          How can i set cursor focus here?

           

          Help me about this.

          I am waiting for your all support.

          • 3. Re: How to set cursor focus to <h:selectOneRadio> during onload?
            Eswara MoorthyNEC Newbie

            Here i use jquery two way.

            The first one is work. But the second is not worked.

            First, The follwoing code is worked.

             

            <a4j:loadScript src="resource://jquery.js"/>
             <script type="text/javascript">   
                     function setFocusRadioField()
                     {
                          jQuery(':input:visible:enabled:first').focus(); 
                      }
             </script>
            
            <body onload="setFocusRadioField();">
            </body>
            
            

             

            Second,

            the following code is not worked. I test the following way:

             

            jQuery('#focusForm\:testRadioId:enabled:first').focus();
            
            

             

            Then,

             

            jQuery('#focusForm\\:testRadioId:enabled:first').focus();
            
            

             

            Then

             

            var id = "#focusForm:testRadioId:enabled:first".replace(/:/g, "\\:");
            jQuery(id).focus();
            
            

             

            I need set cursor focus using id. I don't know where i make mistake using second way.help me about this.

            Thanks in advance.