Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 855355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:03:40+00:00 2026-05-15T08:03:40+00:00

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

  • 0

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.


Update:

Thanks BaluC.

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

But 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 don’t know where i make the error.
Better, I need set the cursor focus using id.
Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T08:03:41+00:00Added an answer on May 15, 2026 at 8:03 am

    Since you tagged jQuery, here’s a jQuery solution:

    $('[id^=focusForm:testRadioId]:enabled:first').focus();
    

    The [id^=name] selector will return all elements starting with name name.

    If your intent is actually to focus the first non-hidden and non-disabled input element of the page, regardless of the input type, then use this:

    $(':input:visible:enabled:first').focus();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Use of rails 3 recaptcha. In view _form.html.erb insert <%= recaptcha_tags %> But when
i am trying to use a simple h:selectOneRadio with a true/false values so here's
use the [] symbol in the name of the form field you are submitting
USE CASE Search Category to find places near Your address (see form screenshot: http://o7.no/KYCj6v
Use default: <input type=radio name=restype value=resdef onfocus=document.getElementById('resupload').disabled = true; document.getElementById('resadres').disabled = true; checked=checked /><br
Use of || (or) I got so many values which I need to compare
I want to use a ui:repeat or any other iterative tag to display a
Use a hidden field will fix my issue... i got it.. Hi All, I
Use Html element SELECT in aspx page like: <SELECT id=MySelection name=MySelection runat=server DataValueField=ID DataTextField=Name></SELECT>
Use http://jobs.sitesixteen.com/ for reference. I'm using YQL for the city, state auto-complete. IF you

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.