cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
Martin
Level V

Radio Button activate Radio Button

Hello,


I have two groups of radio button groups, Group 1 and Group 2. Group 1 has two radio buttons, RB1 and RB2 while Group 2 has two radio buttons RB3 and RB4. When a user selects RB2, I want the script to select RB4 and run the jsl that is behind the selection of RB4. Currently, I can get the script to select RB4 but it does not also run the jsl behind RB4.

Any thoughts would be appreciated.

Thanks,

Martin

1 ACCEPTED SOLUTION

Accepted Solutions
pmroz
Super User

Re: Radio Button activate Radio Button

Forgot that part:

rb4_expr = expr(

    print("Running RB 4 Code");

);

nw = new window("Radio Button Demo",

    hlistbox(

        panelbox("Group 1",

            rb1 = radio box({"RB 1", "RB 2"},

                one_rb = rb1 << get selected;

                if (one_rb == "RB 1",

                // then

                    print("Running RB 1 Code");

                    ,

                // else

                    one_rb == "RB 2",

                    print("Running RB 2 Code");

                    rb4_expr;

                    rb2 << set (2);

                );

            ),

        ),

        panelbox("Group 1",

            rb2 = radio box({"RB 3", "RB 4"},

                one_rb = rb2 << get selected;

                if (one_rb == "RB 3",

                // then

                    print("Running RB 3 Code");

                    ,

                // else

                    one_rb == "RB 4",

                    rb4_expr;

                );

            )

        )

    )

);

View solution in original post

6 REPLIES 6
pmroz
Super User

Re: Radio Button activate Radio Button

rb4_expr = expr(

    print("Running RB 4 Code");

);

nw = new window("Radio Button Demo",

    hlistbox(

        panelbox("Group 1",

            rb1 = radio box({"RB 1", "RB 2"},

                one_rb = rb1 << get selected;

                if (one_rb == "RB 1",

                // then

                    print("Running RB 1 Code");

                    ,

                // else

                    one_rb == "RB 2",

                    print("Running RB 2 Code");

                    rb4_expr;

                );

            ),

        ),

        panelbox("Group 1",

            rb2 = radio box({"RB 3", "RB 4"},

                one_rb = rb2 << get selected;

                if (one_rb == "RB 3",

                // then

                    print("Running RB 3 Code");

                    ,

                / else

                    one_rb == "RB 4",

                    rb4_expr;

                );

            )

        )

    )

);

Martin
Level V

Re: Radio Button activate Radio Button

So this is close.  I was hoping that in the section of the code when RB 2 is selected - RB 4 would be selected automatically - causing the code of RB 4 to run.  Does this make sense?

Thanks

pmroz
Super User

Re: Radio Button activate Radio Button

Forgot that part:

rb4_expr = expr(

    print("Running RB 4 Code");

);

nw = new window("Radio Button Demo",

    hlistbox(

        panelbox("Group 1",

            rb1 = radio box({"RB 1", "RB 2"},

                one_rb = rb1 << get selected;

                if (one_rb == "RB 1",

                // then

                    print("Running RB 1 Code");

                    ,

                // else

                    one_rb == "RB 2",

                    print("Running RB 2 Code");

                    rb4_expr;

                    rb2 << set (2);

                );

            ),

        ),

        panelbox("Group 1",

            rb2 = radio box({"RB 3", "RB 4"},

                one_rb = rb2 << get selected;

                if (one_rb == "RB 3",

                // then

                    print("Running RB 3 Code");

                    ,

                // else

                    one_rb == "RB 4",

                    rb4_expr;

                );

            )

        )

    )

);

Martin
Level V

Re: Radio Button activate Radio Button

So if I understand this correctly, every time RB 2 is selected, "Running RP 2 Code" is printed, then "Running RP 4 Code" is printed via the Expr command (not sure why this can not be just added directly into the RB 2 code, without the Expr command), and then the RP 4 button is selected.  It is not by virture of the RP 4 button being selected that the "Running RP 4 Code" is printed when the RP 2 button is selected.  Correct?

Is the benefit of using the "rb4_expr" reusing the same code for two different parts of the program?

Thanks

pmroz
Super User

Re: Radio Button activate Radio Button

So if I understand this correctly, every time RB 2 is selected, "Running RP 2 Code" is printed, then "Running RP 4 Code" is printed via the Expr command (not sure why this can not be just added directly into the RB 2 code, without the Expr command), and then the RP 4 button is selected.

Yes that's correct.

It is not by virtue of the RP 4 button being selected that the "Running RP 4 Code" is printed when the RP 2 button is selected.  Correct?

Yes.

Is the benefit of using the "rb4_expr" reusing the same code for two different parts of the program?

Yes.

This is straight "call-back" programming for a dialog box.  It's more work than straight linear programming; you have to do more housekeeping.

ms
Super User (Alumni) ms
Super User (Alumni)

Re: Radio Button activate Radio Button

There is an optional argument for rb << set() to run the script besides selecting the button.

rb2 << set( 2, run script( 1 ) );

The script will only run if the button is not already selected, i.e. only the first time unless RB 4 is deselected. PMroz code forces the script to run every time RB 2 is selected/clicked. Compare his code with the below:

nw = New Window( "Radio Button Demo",

  H List Box(

  Panel Box( "Group 1",

  rb1 = Radio Box(

  {"RB 1", "RB 2"},

  one_rb = rb1 << get selected;

  If(

  one_rb == "RB 1",

                // then

  Print( "Running RB 1 Code" ),

                // else

  one_rb == "RB 2",

  Print( "Running RB 2 Code" );

  rb2 << set( 2, run script( 1 ) );

))),

  Panel Box( "Group 1",

  rb2 = Radio Box(

  {"RB 3", "RB 4"},

  one_rb = rb2 << get selected;

  If(

  one_rb == "RB 3",

                // then

  Print( "Running RB 3 Code" ),

                // else

  one_rb == "RB 4", Print( "Running RB 4 Code" )

)))));