Skip to main content
leenda8828
New Participant
October 8, 2020
Answered

Hide/Show a Line of Text

  • October 8, 2020
  • 3 replies
  • 1802 views

Help me Obi-wans. 

 

This is probably elementary for most of you, but I can't figure it out. I would like to have a line of text appear when a specific radio button is selected. I know there are many ways to make a text FIELD hide/show, but I want the TEXT that's on the form to hide/show. Is this possible? Thank you in advance for your superior brains. 

This topic has been closed for replies.
Correct answer ls_rbls

Yes, this is possible with javascript.

 

In my case I prefer to run the code directly from the radio buttons

as a mouse-up action.

 

To do this you must use a pair of radio buttons and set them as mutually exclusive (same field name for both radio buttons but different export value on each.

 

For example, I will name both radio button fields as   "myRadio". And then assign to my first radio button an export value of "Choic1". Then in my second radio button I will assign "Choice2" as the export value.

 

In the radio button with export value of "Choice1" you can use a line os script like this:

 

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

this.getField("myTextField").value = "show this text";

 

And in the radio button with export value "Choice2" use that same line of script above like this:

 

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

this.getField("myTextField").value = "";

 

Like you said there are many other ways to obtain the same result with javascript, but this is my prefer method in my PDFs.

3 replies

leenda8828
New Participant
October 8, 2020

Thank you Is_rbls and NesaNurani - I really appreciate your help. I should have mentioned that I am quite a novice, so while I do understand the use of javascript, I'm still a bit confused. 

 

Initially, I had the line of text as part of the PDF itself (so it was static - but I wanted to show/hide it depending on the answer to another question). Based on your suggestions, I'm thinking that perhaps I should use a different method for the line of text that I want to show/hide. 

 

Maybe an example would help. 

Let's say the question is: "Did you complete these steps?" Answer choices would be shown with radio buttons as either "Yes" or "No." If the person answers "No" then I want a "warning" text to pop up saying (as an example) "Sorry, we cannot complete your request because you've answered "No" to the question above." I would also like it to toggle, so if after initially answering "No" the warning would go away if they change the response to "Yes."

Brainiac
October 8, 2020

You can't hide or control any static text. You COULD cover it up with a white box when you don't want to see it (the white box being a form field) but it's probably better to make the message a form field itself.

leenda8828
New Participant
October 8, 2020

Thank you, Test - I finally figured this out - thank you for this info. I made it a text field then entered my text, then used the "get" instructions above from Is_rbls to make it toggle depending on which radio button is selected. I think it's working. I really appreciate your input!

Nesa Nurani
Community Expert
October 8, 2020

Did you create text with comment tool?

If yes then you can go like this:

If you want to use radio button you would need to create hidden text field to use as calculation because I'm not sure there is option to hide
text via properties use this code in text field custom calculation script:
this.getAnnot(0,"Your text name goes here").hidden = this.getField("Group1").value != "Off" ? false : true;

 

Change "Group1" to your radio button name.

 

To find your text name, select your text and press CTRL+J
now in console paste this code:
this.selectedAnnots[0].name;
and press Enter to get name, now copy that name and put it into code where says "Your text name goes here".

 

If you use checkbox instead of radio button then you wouldn't need hidden text field.
If you choose to go with checkbox add this javascript as checkbox MouseUp event:
this.getAnnot(0,"Your text name goes here").hidden = event.target.value != "Off" ? false : true;

ls_rbls
Community Expert
October 8, 2020

I think I made a mistake Nesa.

 

The user was asking to show/hide the text that is already typed in a text field.

 

If that is the case , I believe he wasn't asking for hiding or showing the text field.

 

I would say, if we use the second line of my script as an example, the other question would be, if the text is going to be static or permanent(always showing), or , are the users going to input data in this field? In which case, is always changing.

 

 

Nesa Nurani
Community Expert
October 8, 2020

I thought he want to show/hide basic text.

If he want to hide text in text field until radio button is checked, maybe to use code in text field to set text color to same as field background and then when radio button is checked to change text color to something else?

ls_rbls
ls_rblsCorrect answer
Community Expert
October 8, 2020

Yes, this is possible with javascript.

 

In my case I prefer to run the code directly from the radio buttons

as a mouse-up action.

 

To do this you must use a pair of radio buttons and set them as mutually exclusive (same field name for both radio buttons but different export value on each.

 

For example, I will name both radio button fields as   "myRadio". And then assign to my first radio button an export value of "Choic1". Then in my second radio button I will assign "Choice2" as the export value.

 

In the radio button with export value of "Choice1" you can use a line os script like this:

 

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

this.getField("myTextField").value = "show this text";

 

And in the radio button with export value "Choice2" use that same line of script above like this:

 

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

this.getField("myTextField").value = "";

 

Like you said there are many other ways to obtain the same result with javascript, but this is my prefer method in my PDFs.