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 6891535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:25:21+00:00 2026-05-27T06:25:21+00:00

How do you get which radio is selected within p:selectOneRadio using javascript/jquery ? Since

  • 0

How do you get which radio is selected within p:selectOneRadio using javascript/jquery ?

Since the p:selectOneRadio uses no radio tags I have no idea how to get the checked option using CSS selectors.

    <p:selectOneRadio onchange="reactToChangedRadio()" >
              <f:selectItem itemLabel="....." itemValue="..." />
              <f:selectItem itemLabel="....." itemValue="..." />
              <f:selectItem itemLabel="....." itemValue="..." />
    </p:selectOneRadio>
  • 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-27T06:25:22+00:00Added an answer on May 27, 2026 at 6:25 am

    You can use the jquery solution or choose a simple javascript solution:

    document.getElementById("myFormId:mySelectId")[0].checked 
    

    See the post from CodeRanch: http://www.coderanch.com/t/210871/JSF/java/selectOneRadio-javascript-value

    UPDATE:
    I must admit that I’m in a dept, and I’m sorry for that but yesterday I haven’t had much time…

    I must say that I haven’t been able to get the radio value in the old fashioned javascript way:

                     <script type="text/javascript">
                          /*  <![CDATA[ */
    
                            function reactToChangedRadio(){
                               alert("I'm in!");
                               var myval;
                                for(i=0;i<3;i++){
                                        if(document.forms['myFormId']['myFormId:myRadio'][i].checked == true ){
                                            myval = document.forms['myFormId']['myFormId:myRadio'].text/value;
                                        }
                                    }
                                    alert( "val = " + myval );
                            }
                        /*    ]]> */
                    </script>
    

    On the other hand, this hard-coded solution works:

                     <script type="text/javascript">
                          /*  <![CDATA[ */
    
                            function reactToChangedRadio(){
                               alert("I'm in");
                               var myval;
                               if(document.forms['myFormId']['myFormId:myRadio'][0].checked == true ){
                                  myval = "first button";
                               }else if(document.forms['myFormId']['myFormId:myRadio'][1].checked == true ){
                                  myval = "second button";
                               }else if(document.forms['myFormId']['myFormId:myRadio'][2].checked == true ){
                                  myval = "third button";
                               }
    
                               alert( "val = " + myval );
                            }
                        /*    ]]> */
                        </script>
    

    ,but of course, because of Primefaces power, there is a server side solution(using ReuqestContext component):

                     <h:form id="myFormId">
                            <p:selectOneRadio id="myRadio" value="#{handleFiles.radioVal}" >
                                <p:ajax event="change" oncomplete="handleComplete(xhr, status, args)" listener="#{handleFiles.testMethod}" />
                                <f:selectItem itemLabel="1" itemValue=" first" />
                                <f:selectItem itemLabel="2" itemValue=" second" />
                                <f:selectItem itemLabel="3" itemValue=" third" />
                            </p:selectOneRadio>
                        </h:form>
    <script type="text/javascript">
     function handleComplete(xhr, status, args) {  
        alert("Selected Radio Value" + args.myRadVal);  
     } 
    </script>
    

    The server side code:

    private String radioVal;
    
    public String getRadioVal() {
        return radioVal;
    }
    
    public void setRadioVal(String radioVal) {
        this.radioVal = radioVal;
    }
    
    public void test(){
        RequestContext context = RequestContext.getCurrentInstance();  
        context.addCallbackParam("myRadVal", radioVal);
        System.out.println("radioVal: "+radioVal);
    }
    

    the ReuqestContext component can be found here: http://www.primefaces.org/showcase-labs/ui/requestContext.jsf (only for PF 3)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two SQL scripts which get called within a loop that accept a
I have the following form(echoed through php), which when a radio button is selected,
can we get the values of the radio buttons , only those which has
I have an application which get copied and run on client machines. The program
We have a project with many dll files which get loaded when the application
I have a datagridview and a combobox which get populated randomly with data. However,
I have a number of CSS attributes and Classes which get applied based on
Like the title says, what's the best way in JavaScript to get all radio
Hay, how can i get the value of this? i.e. which one is selected.
I have two radio buttons and want to post the value of the selected

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.