10 Replies Latest reply on Nov 19, 2009 7:05 AM by Ned Murphy

    How to trap which radio button was selected and its data?

    xxxheeroxxx

      Good day everyone,

       

      Need help on this one. This would be my first post regarding components, specifically radio button.

      Here's goes my problem I have several groups of radio button. And I want to track which radio button on each group was selected, and I will get the data and pass it to a loadVariablesNum function.

       

      Thanks,

       

       

      Any help is very much appreciated.

        • 1. Re: How to trap which radio button was selected and its data?
          Ned Murphy Adobe Community Professional & MVP

          You can use the following to determine which radio within a group is selected and what the data is for that selection...

           

          Selected Radio: radioGroup.selection
          Selected Radio Data: radioGroup.selection.data

          • 2. Re: How to trap which radio button was selected and its data?
            xxxheeroxxx Level 1

            Thank you for replying Sir NedWebs,

             

            The structure of my application is that all of my radio button is inside a movieclip called "contents". And each row has 4 radio button belong to a group, do I have to make an instance name on each of the radio button?

             

            And I have a button that will trigger loadVariablesNum on each group of radio button and which of the 4 radio buttons is selected.

            Here's what I did

             

            =====

            button

            =====             

            instance name    rb1a       rb2b      rb3c     rb4d

             

            group1                radio1    radio2   radio3   radio4

             

            on(release){

                 contents.grp1.rb1a.selection

            }

            • 3. Re: How to trap which radio button was selected and its data?
              Ned Murphy Adobe Community Professional & MVP

              You indicated you wanted to know which radio was clicked, so if you give them each an instance name that will be more determinable, but no, you do not need to assign instance names to each button to have the code work to detect which is selected and what the data of it is.

               

              I am not sure what you are trying to do with the code:

               

              on(release){

                   contents.grp1.rb1a.selection

              }

               

              but whatever it is, you would be using: contents.grp1.selection instead of what you show. It is not a complete bit of coding, so I can't answer beyond that.  I assume you will be doing something similar as to what you did with the checkbox code.

               

              Maybe the following will help you realize a thing or two.  Use this code for the button and see what you get...

               

              on(release){

                   trace(contents.grp1.selection);

                   trace(contents.grp1.selection.data);

              }

               

              Then figure out how you need/want to manipulate that information.

              • 4. Re: How to trap which radio button was selected and its data?
                xxxheeroxxx Level 1

                I have several groups of radio buttons, Do I have to give it an instance name? And all this groups is inside a movieclip called "contents".

                One button triggers the loadVariablesNum function.

                 

                What I did when I'm trying to access the radio button data is like this:

                 

                =========

                button code:

                =========

                giving each radio button in a group an instance name.

                 

                on(release){

                 

                var1 = contents.grp1.rb1a.selection.data // it could be rb1 a, b, c or d.

                loadVariablesNum("http://url/phpfile.php?did="+_root.uid+"&ans=21&val=4", 2); //meaning selecting in group1 radio button 4 and a value of 4

                 

                var2 = contents.grp2.rb2d.selection.data // it could be rb2 a, b, c or d.

                loadVariablesNum("http://url/phpfile.php?did="+_root.uid+"&ans=21&val=1", 2); //meaning selecting in group1 radio button 1 and a value of 1

                 

                }

                 

                ========

                you code:

                ========


                on(release){

                     trace(contents.grp1.selection);

                     trace(contents.grp1.selection.data);

                }

                 

                Am I in the right track Sir NedWebs? When I use ur code above, I got undefined.

                 

                Thanks Sir NedWebs,

                • 5. Re: How to trap which radio button was selected and its data?
                  Ned Murphy Adobe Community Professional & MVP

                  1) Is one of the radios selected when you get that undefined result?  If none is, then you will get undefined as an output.

                   

                  or

                   

                  2) Where is your button relative to the contents mc?  It would need to be on the same timeline as the contents mc for the code you show.

                  • 6. Re: How to trap which radio button was selected and its data?
                    xxxheeroxxx Level 1

                    All the radio buttons is inside the movieclip "contents". And I get the undefined results after I select one of the radio button in the 1st group. And click on the button that triggers loadVariablesNum.

                     

                     

                    Thanks again,

                    • 7. Re: How to trap which radio button was selected and its data?
                      Ned Murphy Adobe Community Professional & MVP

                      You didn't answer my second question.  Is the button in the same timeline as the contents mc?  And now that you mention the buttons function, where are you using that code of mine that you said gives "undefined"?

                       

                      It will be to your benefit to create a new file to resolve this where you simply have some radio buttons and another normal button that uses that blue code.  Once you have that working you should be able to adapt it into your scenario more easily.

                      • 8. Re: How to trap which radio button was selected and its data?
                        xxxheeroxxx Level 1

                        Sorry I forgot,

                         

                        It's on the same timeline.

                         

                        main timeline

                         

                        objects are:

                        contents -> inside is the radio buttons

                        button continue -> holds code for loadVariablesNum

                         

                        I try this code also but the result is undefined.

                         

                        ================

                        button continue code:

                        ================

                         

                        on(release){

                             trace(contents.grp1.selection);

                             trace(contents.grp1.selection.data);

                        }

                         

                        ===========================================

                        trying to revised by me still get the same result = undefined:

                        ===========================================

                        on(release){

                             contents.grp1.selection;

                             var1 = contents.grp1.selection.data;

                             loadVariablesNum("url?did="+_root.uid+"&ans=41&val1", 2);

                        }

                         

                        result val1 = undefined.

                        • 9. Re: How to trap which radio button was selected and its data?
                          xxxheeroxxx Level 1

                          I just break apart the content mc and try your code Sir NedWebs and it works.

                           

                           

                          Thanks a lot, God Bless,

                          • 10. Re: How to trap which radio button was selected and its data?
                            Ned Murphy Adobe Community Professional & MVP

                            You are mixing var1 and val1 in what you show, so I don't know if your problem is simply a typo.

                             

                            In any case, I still recommend you create a simple example file to resolve things.  Put a couple of radio buttons in it, designate one as being selected by default, and keep the default group name.  Then add a button  that uses the code I showed and run it.