Skip to main content
Participant
August 2, 2022
Answered

Checkbox Radio buttons selection to Text

  • August 2, 2022
  • 1 reply
  • 573 views

Hi all,

I hate doing this because I know, at its core, this is easy...but, I'm crash-learning Adobe/Javascript after developing basic interactivity in VB for a document that now is getting transferred to a pdf, and thus losing its VBA'ness. But, enough whining, and onto the issue:

I got two sets of two checkboxes (which, could - and probably should - be radio buttons grouped as two groups of two), lets say Group 1 contains Checkboxes A and B, and Group 2 contains C and D...they are named CBA, CBB, CBC, and CBD respectively. 

I also got a text box that needs to be populated with different text based on the four possible combinations of selections that could be made amongst the CB's. The text box is named "Text2". So essentially, I need a script to replace the text in Text 2 based on the checked or unchecked (or radio'd) nature of the combinations:

CBA-CBC

CBA-CBD

CBB-CBC

CBB-CBD

Any assistance you can provide in putting this code into Acrobat - would be appreciated. 

Thanks, in advance

BN

This topic has been closed for replies.
Correct answer try67

Good riddance to VBA... JS is 100 times better and easier to use!

Anyway, if you want to make them mutually exclusive use check-boxes with the same name, but unique export values. Never use single radio-buttons, though, as they can't be "unticked"!

 

You can use this code as the custom calculation script of "Text 2" (it assumes you have 4 separate check-boxes, but can be easily adjusted to two groups of two):

 

var CBA = this.getField("CBA").valueAsString!="Off";
var CBB = this.getField("CBB").valueAsString!="Off";
var CBC = this.getField("CBC").valueAsString!="Off";
var CBD = this.getField("CBD").valueAsString!="Off";

if (CBA && CBC) event.value = "Some text";
else if (CBA && CBD) event.value = "Some other text"; // etc.
else event.value = "";

 

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
August 2, 2022

Good riddance to VBA... JS is 100 times better and easier to use!

Anyway, if you want to make them mutually exclusive use check-boxes with the same name, but unique export values. Never use single radio-buttons, though, as they can't be "unticked"!

 

You can use this code as the custom calculation script of "Text 2" (it assumes you have 4 separate check-boxes, but can be easily adjusted to two groups of two):

 

var CBA = this.getField("CBA").valueAsString!="Off";
var CBB = this.getField("CBB").valueAsString!="Off";
var CBC = this.getField("CBC").valueAsString!="Off";
var CBD = this.getField("CBD").valueAsString!="Off";

if (CBA && CBC) event.value = "Some text";
else if (CBA && CBD) event.value = "Some other text"; // etc.
else event.value = "";

 

beNeatAuthor
Participant
August 4, 2022

Many Thanks - This was what I needed to develop the solution, listed below! This was able to group the two groups of two checkboxes each, and identify the correct text per combo. 

I DID NOT, however, anticipate Google Chrome's inexecusable inability to render JavaScript if the user is using Chrome to read their pdf's - and thus, this wonderful solution, had to be scrapped. WHAT GIVES!?!?! I know, I know - the users should just use Acrobat Reader, and everything would be fine - but, alas, I'm not in charge of the users - I only develop content - and, however not advisable it is - many users default to using their browser for pdf's (or, don't even know that's what's going on). UGH - that's frustrating and somewhat restrictive on future development. 

I, ultimately, was able to eek out a clunky solution, using the on-board triggers for Mouse Up and Field additions - which, in the eyes of Chrome, "isn't" JavaScript. 

Anywho - didn't want to go more time with thanking you! 

BNeat

 

var CBA = this.getField("Where").valueAsString=="CBA";
var CBB = this.getField("Where").valueAsString=="CBB";
var CBC = this.getField("Type").valueAsString=="CBC";
var CBD = this.getField("Type").valueAsString=="CBD";

if (CBA && CBC) event.value = "Scan the Barcode at Checkout";
else if (CBA && CBD) event.value = "1) Print a copy to take to the store. 2) Scan the barcode at checkout.";
else if (CBB && CBC) event.value = "1) Enter the Gift Card Number. 2) Enter the Pin.";
else if (CBB && CBD) event.value = "1) Enter the Gift Card Number. 2) Enter the Pin.";