Expand my Community achievements bar.

Radio Buttons – How to Hide and make visible multiple / random text fields using two buttons

Avatar

Level 1

Hello, I need to create a form that, All fields are Hidden but  If you select "Dealer Warranty" Radio Button, 9 of the 10 Text Fields will be visible but if you select "Service Technician" only 8 Fields will be visible but not necessarily the same ones.

Example:

I am using:

MAIN.Page1.RadioButtonList.Dealer::click - (JavaScript, client)

if (MAIN.Page1.RadioButtonList.Dealer.selectedIndex == 0)

{ MAIN.Page1.Distributor_Name.presence = "visible";

MAIN.Page1.Machine_Owner.presence = "visible"; }

else { MAIN.Page1.Distributor_Name.presence = "invisible";

MAIN.Page1.Machine_Owner.presence = "invisible"; }

MAIN.Page1.RadioButtonList.Service::click - (JavaScript, client)

if(MAIN.Page1.RadioButtonList.Service.selectedIndex == 0)

{ MAIN.Page1.Distributor_Name.presence = "visible";

MAIN.Page1.Machine_Owner.presence = "visible"; }

else { MAIN.Page1.Distributor_Name.presence = "visible";

MAIN.Page1.Machine_Owner.presence = "visible"; }

But it will only work on one of the fields and not the other.  I need to do this with about 30 Text fields on the page.

Can someone please help!

1 Reply

Avatar

Level 7

This looks like a logic problem.

The first if/else statement says, "When the user clicks the Dealer radio button, check to see if the first instance (or 0th instance) is selected. If it is, then make these visible. If not, make them invisible." The problem is, when you click on a radio button, that button is selected. Also, there is only one instance of each, so the 0th instance is always selected. That means that the statement will always evaluate 'true'.

The second if/else statement has the same problem, plus an additional problem. The if and else clauses are the same.

Here's my suggestion:

  1. comment out or delete what you have now.
  2. select RadioButtonList
  3. open the Object pallette > Binding tab.
  4. verify the values for the two radio buttons.
  5. add code to the 'click' event for RadioButtonList that looks similar to this.

Now, I'm presuming that the value of the first radio button is 0. If it's something else, you can change the code to match what you have or change the value to match the code. Just make sure that their values are different.

If you want to add another radio button, you can just make 3 if statements that aren't nested in the 'click' event. If it gets bigger than that, then a switch statement may be in order.