• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
2

Reset radio group to hidden when form is cleared

Community Beginner ,
May 10, 2024 May 10, 2024

Copy link to clipboard

Copied

I have reached my wits end trying to figure something out unsuccessfully and so I am writing here for the first time ever, hoping the commuty can assist.

 

I've created a benefits enrollment form that has two sets of radio button groups that are connected, "Medical" and "Medical Waive Reason" with the latter having an initial display value of hidden.

 

What I need to happen:

  1. If an employee chooses to waive coverage in the medical plan thus selects the "Decline Coverage" radio button, the "Medical Waive Reason" radio buttons become visible.
  2. If an employee chooses to enroll in the medical plan and selects one of the other "Medical" group radio options (not "Decline"), then the "Medical Waive Reason" radio buttons return to hidden and, if any button was selected, values cleared.
  3. If the entire form is cleared, therefore the "Decline Coverage" radio box is cleared, then the "Medical Waive Reason" radio buttons return to initial state of hidden, values cleared if any.

 

What I've accomplished:

I've managed to successfully solve for items 1 & 2.  On the "Decline Coverage" radio button > Action Tab > Run a JavaScript on mouse up, I used the following script that works:

 

var radio2 = this.getField("Medical Waive Reason");
if (event.target.value=="Off")
{
radio2.display = display.hidden;
radio2.value = "";
}
if (event.target.value=="Med 4- waive")
{
radio2.display = display.visible;
} else {
radio2.display = display.hidden;
radio2.required = false;
radio2.value = "";
}

 

Where I need help:

I cannot figure out the JavaScript for how to return the "Medical Waive Reason" radio group back to the initial Hidden state when "Decline Coverage" is CLEARED.  Can you help solve this mystery???  Please!!!

TOPICS
PDF forms

Views

189

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 10, 2024 May 10, 2024

Copy link to clipboard

Copied

Use a Calculation script to do this, instead of a Mouse Up one. The former is triggered when the form is cleared, the latter isn't. You can use a hidden text field for this. The only thing you need to adjust in your code, basically, is to replace event.target.value with this.getField("Decline Coverage").value.

However, there's an error in your code. If "Medical Waive Reason" is a radio-button group then setting its value to "" will not clear it. You need to set it to "Off".

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 26, 2024 Jun 26, 2024

Copy link to clipboard

Copied

Thank you so much for your response.  Some follow up questions:

 

1. I don't see a place to add a Calculation script to a radio group.  I attach an image here of the Decline Coverage properties options.  Could advise where I can find the area to add a Calculation script?

 

2. I've reviewed your script suggestions and updated to the best of my understanding.  Is the below script now written correctly?  And would the script remain [somewhere] on the Decline Coverage radio button or would it go elsewhere?

var radio2 = this.getField("Medical Waive Reason");
if (this.getField("Decline Coverage").value=="Off")
{
radio2.display = display.hidden;
radio2.value = "Off";
}
if (this.getField("Decline Coverage").value=="Med 4- waive")
{
radio2.display = display.visible;
} else {
radio2.display = display.hidden;
radio2.required = false;
radio2.value = "Off";
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 26, 2024 Jun 26, 2024

Copy link to clipboard

Copied

1. No, you won't find it. As I wrote: You can use a hidden text field for this.

2. The script is written correctly, but the logic behind it is flawed. The second part of it will completely override the first one, so you can remove that part entirely:

if (this.getField("Decline Coverage").value=="Off")
{
radio2.display = display.hidden;
radio2.value = "Off";
}

Another issue is the required property. If you want the field to be required when visible you have to set it as true. Otherwise there's no need to set it as false in your code, as it only needs to happen once.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 27, 2024 Jun 27, 2024

Copy link to clipboard

Copied

LATEST

Hi there,

I guess I'm confused on how to accomplish step 1.  How do I use a hidden text field on a radio button?  I have the Mouse Up script on the final radio button ("Decline Coverage") out of nine.  It sounds like you need me to move the script but I'm not sure to where.  If I need to create a new field, how would it be connected to the radio group?

 

Thanks for being patient with me.  I am completely self-taught and this is something I haven't mastered yet.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines