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!
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.
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")
Copy link to clipboard
Copied
Thank you for your answer.
I replaced my
"=" with "=="
but still not working.
Copy link to clipboard
Copied
Check the JS Console (Ctrl+J) for error messages.
Copy link to clipboard
Copied
Thanks, I checked, and this is what is given as error:
TypeError: x is null
3:Field:Mouse Up
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
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?
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.
Copy link to clipboard
Copied
Sorry. I self-correct. I meant "fields" by writting layers.
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.
Copy link to clipboard
Copied
Here comes my file:
The field of interest is group6>un_jour_precis (where I tried to assign a js comment)
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.
Copy link to clipboard
Copied
Thank you! I would proceed like this.