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

radio button show hide

Participant ,
Apr 23, 2018 Apr 23, 2018

Copy link to clipboard

Copied

I have this JavaScript that works on 5 check boxes. I want to use this on Radio buttons.

There are 5 checkboxes, each has a text field. If you choose button 1, all other text fields hide. Choose button 2, text field 1 comes back, and 2nd txt field hides.

My issue, if using check boxes, after selecting the first checkbox, the first text field hides, if you then decide to pic 2nd checkbox, 1st chk box does not uncheck, but the field hides.

Do I need an else if?

if (event.target.value != "Off") {

// box is checked

this.getField("refusal").display = display.hidden ;

this.getField("IDA unable").display = display.hidden ;

this.getField("IDA ceased").display = display.hidden ;

this.getField("OtherReason").display = display.hidden ;

}

else {

// box is unchecked

this.getField("refusal").display = display.visible ;

this.getField("IDA unable").display = display.visible ;

this.getField("IDA ceased").display = display.visible ;

this.getField("OtherReason").display = display.visible ;

}

Or how is it done with radio buttons.

1-boxe checked.png2-boxes checked.png

TOPICS
PDF forms

Views

6.8K

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
1 ACCEPTED SOLUTION
Community Expert ,
Apr 23, 2018 Apr 23, 2018

Copy link to clipboard

Copied

Ok, so you need radio buttons because the user is supposed to only check one. Then back to my first and second posts.

You only need to handle the Clicked On situation. In fact, since you can't click a radio button off, you don't need an if statement at all, just change the visibility as necessary for each button.

On mouseUp for the first button (and I'm assuming the field name is notificaton cause it's not included in the other code:

this.getField("notification").display = display.visible;

this.getField("refusal").display = display.hidden ;

this.getField("IDA unable").display = display.hidden ;

this.getField("IDA ceased").display = display.hidden ;

this.getField("OtherReason").display = display.hidden ;

For the 2nd Button:

this.getField("notification").display = display.hidden;

this.getField("refusal").display = display.visible;

this.getField("IDA unable").display = display.hidden ;

this.getField("IDA ceased").display = display.hidden ;

this.getField("OtherReason").display = display.hidden ;

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

View solution in original post

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 ,
Apr 23, 2018 Apr 23, 2018

Copy link to clipboard

Copied

You'll need a MousUp script for each radio button. Each script must show/hide fields needed when that button is checked.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
Participant ,
Apr 23, 2018 Apr 23, 2018

Copy link to clipboard

Copied

How is it different than the code I sent. I thought that would work?

Is it in a group of radio buttons, or 5 groups of 1 radio button?

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 ,
Apr 23, 2018 Apr 23, 2018

Copy link to clipboard

Copied

It's almost exactly the same. However, for a checkbox you have to deal with both the off and on clicks, but for a radio button group you only need to worry about the On click, because you can't turn a radio button off.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
Participant ,
Apr 23, 2018 Apr 23, 2018

Copy link to clipboard

Copied

I will need to work on that. I have it working great with check box, but if I select a 2nd checkbox, the field for the first chkbox does not come back.

Same with radio button. As you say, it will not turn off. But I need an on/off. I have 5 text fields, each with a radio button. Select the first and it works, but if I select the 2nd button, no fields come back, because there is nothing to say 'turn on'. This is why I had an IF.....

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 ,
Apr 23, 2018 Apr 23, 2018

Copy link to clipboard

Copied

Radio buttons are like potato chips, you can't have just one. They are always used in a group. It is a one of many selection control. Checkboxes act individually. I don't know your form or what you are trying to do so you have to decide which to use. Is this a one of many situation, or does each line need an independent on/off? 

If each line is independent, then only the text field for that line should be included in the code. The only time you'd include the other text fields is if only one line could be selected at a time.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
Participant ,
Apr 23, 2018 Apr 23, 2018

Copy link to clipboard

Copied

There are 5 check boxes with a corresponding text field, this section requires user to pick 1.

When you pick 1 checkbox, the other 4 text fields hide. when you chose a different checkbox, then the first one would hide is text box and the 2nd choices txt box would appear.

This worked with chkboxes, but once you made a choice, if you change it, the first checkbox does not uncheck, there for hiding all

A link to the PDF - ist section -

I. Reason for Making the New Deposit

This deposit is being made as a result of:

https://cloud.acrobat.com/file/03616199-1cba-43f0-8336-9d46451df924

This deposit is being made as a result of:

1 Notification received of non-viability of original deposit on (date YYYY-MM-DD): ------------

1 Refusal of IDA to accept deposit due to:--------------------

1 IDA unable to furnish sample of original deposit due to:-------------------

1 IDA ceased to carry out duties under Budapest Treaty effective (date YYYY-MM-DD):--------------------

1 Other reason (specify): 2--------------------------

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 ,
Apr 23, 2018 Apr 23, 2018

Copy link to clipboard

Copied

Ok, so you need radio buttons because the user is supposed to only check one. Then back to my first and second posts.

You only need to handle the Clicked On situation. In fact, since you can't click a radio button off, you don't need an if statement at all, just change the visibility as necessary for each button.

On mouseUp for the first button (and I'm assuming the field name is notificaton cause it's not included in the other code:

this.getField("notification").display = display.visible;

this.getField("refusal").display = display.hidden ;

this.getField("IDA unable").display = display.hidden ;

this.getField("IDA ceased").display = display.hidden ;

this.getField("OtherReason").display = display.hidden ;

For the 2nd Button:

this.getField("notification").display = display.hidden;

this.getField("refusal").display = display.visible;

this.getField("IDA unable").display = display.hidden ;

this.getField("IDA ceased").display = display.hidden ;

this.getField("OtherReason").display = display.hidden ;

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
Participant ,
Apr 23, 2018 Apr 23, 2018

Copy link to clipboard

Copied

So a group of 5 radio buttons, in the action of each button, I simply make the corresponding text field visible, the rest hidden, correct?

Many thanks

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 ,
Apr 23, 2018 Apr 23, 2018

Copy link to clipboard

Copied

LATEST

Yes, this is exactly what I said in my first post.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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