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

show/hide textbox on radio button

Explorer ,
Nov 09, 2017 Nov 09, 2017

Copy link to clipboard

Copied

Cheers!

I know that it is an issue that is discussed and solved in various platforms, but i have a very (probably quite simple) issue that I can not solve.

I believe I am missing a small but some important parameter since I am new to js.

Basically, I am creating a pdf form in Acrobat.

I have 6 radio buttons in a group (group name: Group1) and each have different names.

Independent than that I have some text field (layer name: "DayMonth-1") that I would like to display (which is hidden in default) if the user selects for example first radio button (layer name: "un_jour_precis" under Group 1).

I used the following code as a MouseUp Event for my radio button:

var x = this.getField("un_jour_precis");

if (x.value = "Off") {

    this.getField("DayMonth-1").display = display.visible;

}

else {

    this.getField("DayMonth-1").display = display.hidden;

}

But, nothing happens

I would appreciate any corrections/suggestions!

TOPICS
Acrobat SDK and JavaScript , Windows

Views

3.5K

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

correct answers 1 Correct answer

Community Expert , Nov 10, 2017 Nov 10, 2017

OK, I see the issue now. "un_jour_precis" is not a field name, it's the "radio button choice" value of a specific radio-button in the "Group6" field. What you tried to do is a bit tricky, so I wrote for you the code that does it:

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

    this.getField("DayMonth-1").display = display.visible;

} else {

    this.getField("DayMonth-1").display = display.hidden;

}

You should apply it to ​all of the radio-buttons in the group for it to work correctly.

Votes

Translate

Translate
Community Expert ,
Nov 09, 2017 Nov 09, 2017

Copy link to clipboard

Copied

You've made a classic mistake of assigning a value instead of comparing it...

Change this line:

if (x.value = "Off")

To:

if (x.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
Explorer ,
Nov 09, 2017 Nov 09, 2017

Copy link to clipboard

Copied

Thank you for your answer.

I replaced my

"=" with "=="

but still not working.

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 ,
Nov 09, 2017 Nov 09, 2017

Copy link to clipboard

Copied

Check the JS Console (Ctrl+J) for error messages.

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
Explorer ,
Nov 09, 2017 Nov 09, 2017

Copy link to clipboard

Copied

Thanks, I checked, and this is what is given as error:

TypeError: x is null

3:Field:Mouse Up

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 ,
Nov 09, 2017 Nov 09, 2017

Copy link to clipboard

Copied

X is null because the field name is incorrect.

Here is an article that discussed exactly the thing you want to do:

https://acrobatusers.com/tutorials/show_hide_fields

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
Explorer ,
Nov 10, 2017 Nov 10, 2017

Copy link to clipboard

Copied

Thank you for commenting and the reference. I already checked that article before posting this question.

Nevertheless it's sample#2 for radio buttons is not corresponding exactly what I ask.

Plus, I did apply their advice such as:

this.getField("DayMonth-1").display = display.visible;  else.....

You wrote  "X is null because the field name is incorrect." but I double checked my field names and text in js. And they are the same. Did you mean something else?

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 ,
Nov 10, 2017 Nov 10, 2017

Copy link to clipboard

Copied

It means what Thom said. You keep referring to layers... Is this a layer or a field? The two are not the same, you know.

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
Explorer ,
Nov 10, 2017 Nov 10, 2017

Copy link to clipboard

Copied

Sorry. I self-correct. I meant "fields" by writting layers.

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 ,
Nov 10, 2017 Nov 10, 2017

Copy link to clipboard

Copied

OK. Then the field-name you specified is incorrect. Keep in mind it's case-sensitive.

If you still can't get it to work you will need to share either a screenshot of the field and the code, or (better yet) the actual file.

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
Explorer ,
Nov 10, 2017 Nov 10, 2017

Copy link to clipboard

Copied

Here comes my file:

https://we.tl/RjgfKKvF0H

The field of interest is group6>un_jour_precis (where I tried to assign a js comment)

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 ,
Nov 10, 2017 Nov 10, 2017

Copy link to clipboard

Copied

OK, I see the issue now. "un_jour_precis" is not a field name, it's the "radio button choice" value of a specific radio-button in the "Group6" field. What you tried to do is a bit tricky, so I wrote for you the code that does it:

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

    this.getField("DayMonth-1").display = display.visible;

} else {

    this.getField("DayMonth-1").display = display.hidden;

}

You should apply it to ​all of the radio-buttons in the group for it to work correctly.

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
Explorer ,
Nov 10, 2017 Nov 10, 2017

Copy link to clipboard

Copied

LATEST

Thank you! I would proceed like this.

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