Copy link to clipboard
Copied
Hi all,
First time poster, long time lurker. 🙂
Am a bit of an Adobe newbie - especially on JavaScript so am hoping someone can kindly assist/advise?
I am helping develop a form with an existing dropdown (yes/no) question where depending on if 'yes' or 'no' is selected, subsequent questions are presented to the user based on their selection.
I've been asked if it's possible to do this with check boxes (instead of a dropdown). Given the question is mutually exclusive (must be either 'yes' or 'no'), I thought radio buttons might make more sense here - however, when I go into the radio button field properties, I noted there is no 'calculate' tab (as that might appear when using the dropdown field for instance). And with no calculate tab, I am unable to identify if/where any javascript calculation would go (if at all possible?).
So I guess my question is if it's possible to convert the existing javascript (used in the dropdown) to either radio buttons or check boxes (the subsequent form follow up questions remain the same, it's just an 'aesthetic' change requested by the team who use/manage the form.
Hopefully the above makes sense. Happy to clarify or provide further details/screens if required.
Cheers!
Copy link to clipboard
Copied
In checkbox/radio buttons you need to use 'Action' tab for example as 'Mouse UP' and then select 'Run a JavaScript' and put script there, but unlike calculate tab it only runs script when you click on that field (which can be good in some cases) because calculate script runs every time you make change in your file, and you may not need script to run all the time.
You can also make checkboxes mutually exclusive by giving both checkboxes same name but give one checkbox export value of 'Yes' and other 'No', which can be better than radio button because you can uncheck them, and you can't do that with radio buttons. You will probably need script in both checkboxes to show/hide fields, or you can even put script in hidden text field as calculate script if needed. If you post your script or your file we can be of better assistance.
Copy link to clipboard
Copied
Hi Nesa, many thanks for your reply and sorry for the delay getting back to you - have been offline from work for a few days since I posted my original query.
Thanks for the suggestion on the checkboxes, that may be the better option here from a user POV.
Have attached the PDF page and some screenshots of the 'yes' and 'no' state when selected in the dropdown list - these javascripts would ideally then need to be converted to be used on the 2 new checkboxes below the dropdown.
Bizarrely, when I click on the dropdown (the javascript works) - however, when I visit the calculate tab, the javascript is not show in the custom calculation section (but is still recorded in the javascript editor) - have come across this a few times on my various forms so I'm not sure if that may suggest an issue with my Adobe Acrobat DC perhaps...Hopefully you will be able to see the Javascript calculation on your end.
In any case, this was the javascript used for the dropdown I believe
var e = this.getField("MultidisciplinaryPMProgram");
if ((e.value == 1) ) {
this.getField("Header2").display = display.hidden;
this.getField("Header2Ans").display = display.hidden;
this.getField("Button1").display = display.hidden;
this.getField("TypeOfProgram1").display = display.visible;
this.getField("TypeOfProgram2").display = display.visible;
this.getField("TypeOfProgram3").display = display.visible;
this.getField("DateOfProgCompletion1").display = display.visible;
this.getField("DateOfProgCompletion2").display = display.visible;
this.getField("DateOfProgCompletion3").display = display.visible;
this.getField("MDPMWorkersResponseRow1").display = display.visible;
this.getField("MDPMWorkersResponseRow2").display = display.visible;
this.getField("MDPMWorkersResponseRow3").display = display.visible;
}
else {
this.getField("Header2").display = display.visible;
this.getField("Header2Ans").display = display.visible;
this.getField("Button1").display = display.visible;
this.getField("TypeOfProgram1").display = display.hidden;
this.getField("TypeOfProgram2").display = display.hidden;
this.getField("TypeOfProgram3").display = display.hidden;
this.getField("DateOfProgCompletion1").display = display.hidden;
this.getField("DateOfProgCompletion2").display = display.hidden;
this.getField("DateOfProgCompletion3").display = display.hidden;
this.getField("MDPMWorkersResponseRow1").display = display.hidden;
this.getField("MDPMWorkersResponseRow2").display = display.hidden;
this.getField("MDPMWorkersResponseRow3").display = display.hidden;
}
Copy link to clipboard
Copied
Script is not in a dropdown field, it's actually in a text field named "Text3" but you made it small, so it's hard to see.
Copy link to clipboard
Copied
Many thanks Nesa, good pick up - the last round of changes were made before Christmas so I can't recall how or why the thinking of putting the formula into such a small text box ( a colleague who was familiar with Javascript helped me at the time). Perhaps your earlier reply and the 'hidden text field' was the reason?
I've managed to make the checkboxes mutually exclusive and renamed them 'MultiDisciplinaryPMPCB'. 🙂
Though now the JavaScript I tried to repurpose from that text field doesn't seem to be working as I'd hoped. Not sure if you might be able to see why?
For the 'YES' checkbox, I used this script.
var e = this.getField("MultiDisciplinaryPMPCB");
if ((e.value == 1) ) {
this.getField("Header2").display = display.hidden;
this.getField("Header2Ans").display = display.hidden;
this.getField("Button1").display = display.hidden;
this.getField("TypeOfProgram1").display = display.visible;
this.getField("TypeOfProgram2").display = display.visible;
this.getField("TypeOfProgram3").display = display.visible;
this.getField("DateOfProgCompletion1").display = display.visible;
this.getField("DateOfProgCompletion2").display = display.visible;
this.getField("DateOfProgCompletion3").display = display.visible;
this.getField("MDPMWorkersResponseRow1").display = display.visible;
this.getField("MDPMWorkersResponseRow2").display = display.visible;
this.getField("MDPMWorkersResponseRow3").display = display.visible;
}
else {
this.getField("Header2").display = display.visible;
this.getField("Header2Ans").display = display.visible;
this.getField("Button1").display = display.visible;
this.getField("TypeOfProgram1").display = display.hidden;
this.getField("TypeOfProgram2").display = display.hidden;
this.getField("TypeOfProgram3").display = display.hidden;
this.getField("DateOfProgCompletion1").display = display.hidden;
this.getField("DateOfProgCompletion2").display = display.hidden;
this.getField("DateOfProgCompletion3").display = display.hidden;
this.getField("MDPMWorkersResponseRow1").display = display.hidden;
this.getField("MDPMWorkersResponseRow2").display = display.hidden;
this.getField("MDPMWorkersResponseRow3").display = display.hidden;
}
And for the NO value checkbox:
var e = this.getField("MultidisciplinaryPMPCB");
if ((e.value == 1) ) {
this.getField("Header2").display = display.hidden;
this.getField("Header2Ans").display = display.hidden;
this.getField("Button1").display = display.hidden;
this.getField("TypeOfProgram1").display = display.visible;
this.getField("TypeOfProgram2").display = display.visible;
this.getField("TypeOfProgram3").display = display.visible;
this.getField("DateOfProgCompletion1").display = display.visible;
this.getField("DateOfProgCompletion2").display = display.visible;
this.getField("DateOfProgCompletion3").display = display.visible;
this.getField("MDPMWorkersResponseRow1").display = display.visible;
this.getField("MDPMWorkersResponseRow2").display = display.visible;
this.getField("MDPMWorkersResponseRow3").display = display.visible;
}
else {
this.getField("Header2").display = display.visible;
this.getField("Header2Ans").display = display.visible;
this.getField("Button1").display = display.visible;
this.getField("TypeOfProgram1").display = display.hidden;
this.getField("TypeOfProgram2").display = display.hidden;
this.getField("TypeOfProgram3").display = display.hidden;
this.getField("DateOfProgCompletion1").display = display.hidden;
this.getField("DateOfProgCompletion2").display = display.hidden;
this.getField("DateOfProgCompletion3").display = display.hidden;
this.getField("MDPMWorkersResponseRow1").display = display.hidden;
this.getField("MDPMWorkersResponseRow2").display = display.hidden;
this.getField("MDPMWorkersResponseRow3").display = display.hidden;
}
Copy link to clipboard
Copied
In "NO" you used "MultidisciplinaryPMPCB" 'd' should be 'D'.
Also, in both checkboxes you use: e.value == 1 if they are mutually exclusive they can't have the same export value.
'else' part will work only when you uncheck checkbox manually, it won't work if let's say you select "YES" and then you select "NO".
Copy link to clipboard
Copied
Hi Nesa,
Thanks again and sorry for the delayed response on my part. Juggling a few pieces of work on the go 🙂
I have fixed the 'NO' checkbox with the fixed typo & also changing the e.value '==1' to '==0'
Unfortunately, I'm still having troubles trying to get the script to work (currently, nothing happens with either YES or NO boxes checked). Would this be due to the 'else' part perhaps? Any further assistance would be much appreciated as I'm not sure where else to turn for help 🙂
YES checkbox has the following script
var e = this.getField("MultidisciplinaryPMPCB");
if ((e.value == 1) ) {
this.getField("Header2").display = display.hidden;
this.getField("Header2Ans").display = display.hidden;
this.getField("Button1").display = display.hidden;
this.getField("TypeOfProgram1").display = display.visible;
this.getField("TypeOfProgram2").display = display.visible;
this.getField("TypeOfProgram3").display = display.visible;
this.getField("DateOfProgCompletion1").display = display.visible;
this.getField("DateOfProgCompletion2").display = display.visible;
this.getField("DateOfProgCompletion3").display = display.visible;
this.getField("MDPMWorkersResponseRow1").display = display.visible;
this.getField("MDPMWorkersResponseRow2").display = display.visible;
this.getField("MDPMWorkersResponseRow3").display = display.visible;
}
else {
this.getField("Header2").display = display.visible;
this.getField("Header2Ans").display = display.visible;
this.getField("Button1").display = display.visible;
this.getField("TypeOfProgram1").display = display.hidden;
this.getField("TypeOfProgram2").display = display.hidden;
this.getField("TypeOfProgram3").display = display.hidden;
this.getField("DateOfProgCompletion1").display = display.hidden;
this.getField("DateOfProgCompletion2").display = display.hidden;
this.getField("DateOfProgCompletion3").display = display.hidden;
this.getField("MDPMWorkersResponseRow1").display = display.hidden;
this.getField("MDPMWorkersResponseRow2").display = display.hidden;
this.getField("MDPMWorkersResponseRow3").display = display.hidden;
}
NO checkbox now has the following javascript:
var e = this.getField("MultidisciplinaryPMPCB");
if ((e.value == 0) ) {
this.getField("Header2").display = display.hidden;
this.getField("Header2Ans").display = display.hidden;
this.getField("Button1").display = display.hidden;
this.getField("TypeOfProgram1").display = display.visible;
this.getField("TypeOfProgram2").display = display.visible;
this.getField("TypeOfProgram3").display = display.visible;
this.getField("DateOfProgCompletion1").display = display.visible;
this.getField("DateOfProgCompletion2").display = display.visible;
this.getField("DateOfProgCompletion3").display = display.visible;
this.getField("MDPMWorkersResponseRow1").display = display.visible;
this.getField("MDPMWorkersResponseRow2").display = display.visible;
this.getField("MDPMWorkersResponseRow3").display = display.visible;
}
else {
this.getField("Header2").display = display.visible;
this.getField("Header2Ans").display = display.visible;
this.getField("Button1").display = display.visible;
this.getField("TypeOfProgram1").display = display.hidden;
this.getField("TypeOfProgram2").display = display.hidden;
this.getField("TypeOfProgram3").display = display.hidden;
this.getField("DateOfProgCompletion1").display = display.hidden;
this.getField("DateOfProgCompletion2").display = display.hidden;
this.getField("DateOfProgCompletion3").display = display.hidden;
this.getField("MDPMWorkersResponseRow1").display = display.hidden;
this.getField("MDPMWorkersResponseRow2").display = display.hidden;
this.getField("MDPMWorkersResponseRow3").display = display.hidden;
}
Copy link to clipboard
Copied
Apologies, just realised this is the 'old' script! (too many instances of Adobe open...). Apparently I can't edit posts until I've reached a certain rank so am posting an updated response with the 'latest' version of the javascript :)
YES:
var e = this.getField("MultiDisciplinaryPMPCB");
if ((e.value == 1) ) {
this.getField("Header2").display = display.hidden;
this.getField("Header2Ans").display = display.hidden;
this.getField("Button1").display = display.hidden;
this.getField("TypeOfProgram1").display = display.visible;
this.getField("TypeOfProgram2").display = display.visible;
this.getField("TypeOfProgram3").display = display.visible;
this.getField("DateOfProgCompletion1").display = display.visible;
this.getField("DateOfProgCompletion2").display = display.visible;
this.getField("DateOfProgCompletion3").display = display.visible;
this.getField("MDPMWorkersResponseRow1").display = display.visible;
this.getField("MDPMWorkersResponseRow2").display = display.visible;
this.getField("MDPMWorkersResponseRow3").display = display.visible;
}
else {
this.getField("Header2").display = display.visible;
this.getField("Header2Ans").display = display.visible;
this.getField("Button1").display = display.visible;
this.getField("TypeOfProgram1").display = display.hidden;
this.getField("TypeOfProgram2").display = display.hidden;
this.getField("TypeOfProgram3").display = display.hidden;
this.getField("DateOfProgCompletion1").display = display.hidden;
this.getField("DateOfProgCompletion2").display = display.hidden;
this.getField("DateOfProgCompletion3").display = display.hidden;
this.getField("MDPMWorkersResponseRow1").display = display.hidden;
this.getField("MDPMWorkersResponseRow2").display = display.hidden;
this.getField("MDPMWorkersResponseRow3").display = display.hidden;
}
NO:
var e = this.getField("MultiDisciplinaryPMPCB");
if ((e.value == 0) ) {
this.getField("Header2").display = display.hidden;
this.getField("Header2Ans").display = display.hidden;
this.getField("Button1").display = display.hidden;
this.getField("TypeOfProgram1").display = display.visible;
this.getField("TypeOfProgram2").display = display.visible;
this.getField("TypeOfProgram3").display = display.visible;
this.getField("DateOfProgCompletion1").display = display.visible;
this.getField("DateOfProgCompletion2").display = display.visible;
this.getField("DateOfProgCompletion3").display = display.visible;
this.getField("MDPMWorkersResponseRow1").display = display.visible;
this.getField("MDPMWorkersResponseRow2").display = display.visible;
this.getField("MDPMWorkersResponseRow3").display = display.visible;
}
else {
this.getField("Header2").display = display.visible;
this.getField("Header2Ans").display = display.visible;
this.getField("Button1").display = display.visible;
this.getField("TypeOfProgram1").display = display.hidden;
this.getField("TypeOfProgram2").display = display.hidden;
this.getField("TypeOfProgram3").display = display.hidden;
this.getField("DateOfProgCompletion1").display = display.hidden;
this.getField("DateOfProgCompletion2").display = display.hidden;
this.getField("DateOfProgCompletion3").display = display.hidden;
this.getField("MDPMWorkersResponseRow1").display = display.hidden;
this.getField("MDPMWorkersResponseRow2").display = display.hidden;
this.getField("MDPMWorkersResponseRow3").display = display.hidden;
}
Copy link to clipboard
Copied
Well, the script will work, but you are showing/hiding same fields in both script.
Perhaps you want to replace fields from 'else' and 'if' in 'NO' field script?
Copy link to clipboard
Copied
Do you want the value of the radio button to changed based on a calculation script? Or are you using the calculation script to set some other value based on the radio button?
You can read more about calculations here:
https://www.pdfscripting.com/public/Calculating-field-values-and-more.cfm
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more