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

Creating form in Adobe and summarizing choices

Community Beginner ,
Apr 21, 2020 Apr 21, 2020

Copy link to clipboard

Copied

Hello,

I am new to Acrobat creation documents and asking for help here - thanks in advance.

I need to create form which has: around 40 parts/questions (=number), Each question has varienty of chocies (only one can be picked), each but first choice has its mark (=letter).

 

Example:

1. Body BMI

      normal

      A. light overweight

      B. light underweight

      C. obese....

 

I created text fields with radio buttons for it. But in the end I need to somehow export all answers/choices to one text line in the same document like this: ´´1B (for choice BMI - light underweight), 2C..´´.

If the first option (normal without a letter) is chosen, it should be omitted when exporting.

 

Would someone advice if this is doable, maybe there are some tutorials for similar types of forms anyone can recommend ?

thanks for help in advance

 

TOPICS
How to , PDF forms

Views

1.3K

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 2 Correct answers

Community Expert , Apr 22, 2020 Apr 22, 2020

Hi,

 

This can be easily done with a drop down menu containing  choices and  a custom calculation script  in the text field that you need those values exported to.

 

See slide belowdropdown.png

 

Steps:

 

  1. Create a dropdown menu --  In my example I will use the name "Dropdown2"  for this object. To add your items add your items to it right click on this field object, select "Properties" from the context menu, and goto the "Options" tab. Once you finish adding your items see below that section , there is tick box "Co
...

Votes

Translate

Translate
Community Expert , Jun 27, 2020 Jun 27, 2020

I was asked to help out, so here's my method of doing something like that, without having to rename any fields:

 

var values = [];
for (var i=1; i<=37; i++) {
	for (var j="A".charCodeAt(0); j<="C".charCodeAt(0); j++) {
		var fname = "Text"+i+String.fromCharCode(j);
		var f = this.getField(fname);
		if (f==null) {
			console.println("Error! Can't find the field: " + fname);
			continue;
		}
		if (f.valueAsString!="") values.push(f.valueAsString);
	}
}
event.value = values.join(", ");

 

Votes

Translate

Translate
Community Expert ,
Apr 22, 2020 Apr 22, 2020

Copy link to clipboard

Copied

Hi,

 

This can be easily done with a drop down menu containing  choices and  a custom calculation script  in the text field that you need those values exported to.

 

See slide belowdropdown.png

 

Steps:

 

  1. Create a dropdown menu --  In my example I will use the name "Dropdown2"  for this object. To add your items add your items to it right click on this field object, select "Properties" from the context menu, and goto the "Options" tab. Once you finish adding your items see below that section , there is tick box "Commit Selected Value immediately";  make sure to check that. Click OK.
  2. Create a text field -- You will create a text field object and add a custom calculation script. Righ-click on it, select Properties from the context menu, and goto the "Calculate" tab. In the section below in that dialogue box see tick the radio button labeled " Custom calculation script" and then click on the button "Edit".  Copy the script below and paste it in the calcuation script editing window, then Click OK , then close.

 

 

/*Declaring variables--this line grabs the value that is displayed in the dropdown when the user makes a selection*/

var BMI = this.getField("Dropdown2").valueAsString;

/* and these variables will be used to reflect what should appear in this text field when a user choose a listed item in "Dropdown2" combo box */

var over = "1A (for choice BMI - light overweight)";
var under = "1B (for choice BMI - light underweight)";
var obese = "1C (for choice BMI - obese)";

/* the following lines are conditions. If Dropdown2  is blank or the user selects "normal" nothing is displayed */

if ( (BMI == "") || (BMI== "normal") ) event.value ="";

/*the following conditions are self explanatory */
 
else if (BMI =="A. light overweight") event.value = over;
else if (BMI =="B. light underweight") event.value = under;
else if (BMI =="C. obese") event.value = obese;
 

      

 

 

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 Beginner ,
Apr 27, 2020 Apr 27, 2020

Copy link to clipboard

Copied

Thank you very much, this was what I was looking for an as well it is easy to use for all other characteristics in the document, great !

 

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 Beginner ,
Apr 27, 2020 Apr 27, 2020

Copy link to clipboard

Copied

Hi again, so I created as adviced and it all worked.

However there are a lot characteristics from my questionare for which more than one option is possible..

I searched and it looks like checkboxes would be better. Is there another script I can use to export picked choice to separate text field please ?

Example what is the desired result:

 

Question 17. Diseases in close family members

 

none

A. high blood pressure

B. diabetes

C. obesity

D. cancer

E. heart attack

F. stroke

 

more options can be picked, result in text field for example. 17ACE for picked options A,C,E.

 

Many thanks in advance

 

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 ,
Apr 27, 2020 Apr 27, 2020

Copy link to clipboard

Copied

Hi,

 

Yes that is actually a little easier.

 

Create the checkboxes  and assign a custom export value to it.  For example: 

 

For checbox A   17A (for choice Diseases in close Family Memebers - high blood pressure)
For checbox B   17B (for choice Diseases in close Family Memebers - diabetes)
For checbox C   17C (for choice Diseases in close Family Memebers - obesity)
For checbox D   17D (for choice Diseases in close Family Memebers - cancer)
For checbox E   17E (for choice Diseases in close Family Memebers - heart attack)
For checbox F   17F (for choice Diseases in close Family Memebers - stroke)

 

See slide below:

checkbox2.png

 

Then add a custom calcution script to the textfield that corresponds to each checkbox like this:

 

var a = this.getField("A").value;

if (a=="Off") event.value ="";
else if (a != "Off") event.value = a;

 

 

It would behave like this:

 

checkbox3.png

 

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 Beginner ,
Apr 28, 2020 Apr 28, 2020

Copy link to clipboard

Copied

Thank you ! Looks like better option.

Would you please recommend what script which can concatenate data from filled text fields to one field ?

It would look like for example: 1A, 3C, 7I, 8B... (in one box)

 

I named each text field like ´´Text17A´´ so it matches picked option and they are logically following each other.

 

I tried to apply this script I use in my other documents:

 

event.value =

this.getField("Text3A").valueAsString + ","..

 

but there are in total tens of Text fields like this in which can be the option, is there a script where I can command: ´´show values from all boxes in range Text1A - Text37C with data together, separate it by commas and skip empty fields ´´ or is it too complicated?

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 ,
Apr 28, 2020 Apr 28, 2020

Copy link to clipboard

Copied

Yes this is possible.

 

This is a little more trickier but it can be easily  achieved with IF and ELSE conditional statements.

 

This is also a different inquiry from your original question.Are you looking into learning javasrcript ?  Here is a great start: https://www.pdfscripting.com/public/Calculating-field-values-and-more.cfm

 

And read this tutorial from Thom Parker to get a more thorough idea: https://acrobatusers.com/tutorials/conditional-execution/index.html

 

For example, if you go here: https://www.w3schools.com/jsref/jsref_if.asp  look at how the conditions are constructed.

 

So in your case,  what you're trying to do is something like:

 

if (checbox1 and checkbox 2 are checked) then get the export value of checbox1 + checkbox2 and put it here;

else if(checkbox1 is checked but not checkbox2) then get checkbox1 export value and put it here;

else if ( none are cecked) just leave the field blank;

 

 

 

 

   

 

 

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 Beginner ,
May 04, 2020 May 04, 2020

Copy link to clipboard

Copied

Thanks a lor for those resources, I know little about it but I am interested.

I probably said it incorrectly, sorry. The ultimate goal is that I have one text field output with values from all choices together - this line is copied and used for another documents and purposes (it is some kind of our internal code).

I am trying to get into this if/else conditions, however it is still not clear to me, I think this is too complicated for my beginner skill now - if I am able to write the script like this as there are aprox. 40 questions with total 200 checkboxes and the combinations what can be checked/unchecked are many.

I created the form with exporting value of checkbox in textbox next to it (not looking good, but not important). Can I use some different code for combinig contents of those fields or is it better to use if ?

 

281326_0-1588612356743.png

Thanks for help and your time

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 ,
May 06, 2020 May 06, 2020

Copy link to clipboard

Copied

Hi,

 

Sorry for this late reply.

 

Please  share the code you're using to concatenate those string values? I want to check something.

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 ,
May 31, 2020 May 31, 2020

Copy link to clipboard

Copied

Hi,

 

Just following up to see if you were able to get this project sorted out.

 

Thank you.

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 Beginner ,
Jun 24, 2020 Jun 24, 2020

Copy link to clipboard

Copied

Hello, I apologize for late reply.

 

For now I am using like this

 

- I have created text field next to each checkbox option with code like this for example:

 

var c = this.getField("34C").value;

if (c=="Off") event.value ="";
else if (c != "Off") event.value = c;

 

- then in the end I have one field with code to include values from all the text fields with values next to checkboxes, for example:

 

var s1 = this.getField("Text3A").valueAsString;
if (s1=="") event.value = "";
var s2 = this.getField("Text3B").valueAsString;
if (s2=="") event.value = "";
var s3 = this.getField("Text3C").valueAsString;
if (s3=="") event.value = "";
var s4 = this.getField("Text3D").valueAsString;
if (s4=="") event.value = "";

 

event.value=
s1+""+
s2+""+
s3+""+
s4+""+

 

etc..I did this for all options so the code is really long, but I did not figure out how to write it so it is like a set of all values - something similar that is in excel formulas - (A1:A345...).

 

 

 

 

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 ,
Jun 26, 2020 Jun 26, 2020

Copy link to clipboard

Copied

Hi!

 

To answer you prior question:

 

  • is there a script where I can command: ´´show values from all boxes in range Text1A - Text37C with data together, separate it by commas and skip empty fields ´´ or is it too complicated?

 

Is not that complicated.

 

What you're referring to is about how the cells are organized in a range in  MS Excel for calculation.

 

In Acrobat JavaScript this is done in a similar fashion using an array.

 

You use the getArray method to get the child fields that belong to a parent field with the same prefixed name, and of course,  together with the aid of an "IF or ELSE" condition.

 

See my example below which I took from the JavaScript API Reference, Field methods, page 416:

 

 

 

var f = getField("Text3");
if ( f !== "" ) {
var a = f.getArray();
var v = "";
for (j =0 ; j < a.length ; j++)  v += (a[ j ].value+" ")
event.value = v;
}

else event.value ="";

 

 

 

In the example above you can use something similar but the complicated part in your case would be the time consuming task of renaming all of thos etext fields that you have and also changing their names on each line of code for it to work.

 

 

Now that I provided you with the code it should be a lot easier if you just delete all of those text fields and recreate them using the appropriate naming convention instead of manually changing them one by one.

 

Trust me, I just learned this the hard way recently. And the getArray method won't work if you have different field names like the way you have it now:

 

var s1 = "this.getField("Text3A").valueAsString". 

 

All of your fields that are named with Text3 should be prefixed by adding a period like this:

 

Text3.A

 

So Text3 is considered the parent field name in this context, and every other field like Text3.A, Text3.B, Text3.C  and such, would be referred to and treated  as the children fields.

 

The array loop example above just focuses on the children fields that have a value and it will add up all of  these  values together and ignore the empty or NULL ones during the loop.

 

Also as you can see in that examlpe, I added a spcae to separate those valued from one another. However,  I'm stuck right now with figuring out  how to separate them with a coma. I am not that knowledgeable in javascript yet. So this other part involves additional scripting that I am not too familiarized with.

 

Maybe converting the array to a string and joining the array with a coma can be accomplished using these other  examples:

 

https://stackoverflow.com/questions/39771131/how-to-convert-array-into-comma-separated-string-in-jav...

 

 

 

 

 

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 ,
Jun 27, 2020 Jun 27, 2020

Copy link to clipboard

Copied

I was asked to help out, so here's my method of doing something like that, without having to rename any fields:

 

var values = [];
for (var i=1; i<=37; i++) {
	for (var j="A".charCodeAt(0); j<="C".charCodeAt(0); j++) {
		var fname = "Text"+i+String.fromCharCode(j);
		var f = this.getField(fname);
		if (f==null) {
			console.println("Error! Can't find the field: " + fname);
			continue;
		}
		if (f.valueAsString!="") values.push(f.valueAsString);
	}
}
event.value = values.join(", ");

 

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 ,
Jun 27, 2020 Jun 27, 2020

Copy link to clipboard

Copied

Amazing!

 

What a beast!

 

Thank you so much as usual.

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 Beginner ,
Jul 22, 2020 Jul 22, 2020

Copy link to clipboard

Copied

LATEST

Worked like a charm! Many thanks both for help !

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