Copying items into a single field in order they are selected

Community Beginner ,
Apr 17, 2021 Apr 17, 2021

Copy link to clipboard

Copied

Hello. 

 

On my PDF (created in Acrobat Pro), I currently have a button which copies selected items into a single field when pressed using the following script:

 

if(4==app.alert("Retrieve Introduction Items?",1,2)) {

var total = ""; for(var i=1; i<=30; i++){ if(this.getField("Box"+i).valueAsString != "Off") total+=this.getField("Text"+i).valueAsString+"\n";} this.getField("Sum1").value = total

}

 

The above script will pull the selected items through in a set order. However, is there a way for items to be coped into a list as they are selected, appearing in the target field in the order the user selects them? 

thanks 

Mark

TOPICS
Create PDFs, PDF forms

Views

63

Likes

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

Most Valuable Participant , Apr 17, 2021 Apr 17, 2021
You can do it using this function: function mouseUpBox() { var summaryTextField = this.getField("Sum1"); var summary = summaryTextField.valueAsString; var textValue = this.getField(event.target.name.replace("Box", "Text")).valueAsString; if (event.target.value=="Off") { summary = summary.replace(textValue + "\r", ""); summaryTextField.value = summary; } else summaryTextField.value+=textValue+"\r"; } Add it as a doc-level script, and then call it from the Mouse Up event of each check-b...

Likes

Translate

Translate
Most Valuable Participant ,
Apr 17, 2021 Apr 17, 2021

Copy link to clipboard

Copied

That will require a more complex solution. You could add a code to each one of the check-boxes that adds the corresponding text field when is it clicked. But you would also need to do the reverse, ie. remove the text from the text field when the check-box is unticked.

I don't know how your file is set up, but if the user can edit the text in the text field after clicking the check-box that would not be possible, I think, or least much more complicated.

Likes

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 17, 2021 Apr 17, 2021

Copy link to clipboard

Copied

Thanks, that makes sense.  The end user won't be editing the text, so that shouldn't be too much of an issue.  

Likes

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 17, 2021 Apr 17, 2021

Copy link to clipboard

Copied

I think i've found a solution - just putting a caluclation script on the target box as follows'

 

var items = []; if (this.getField("Box28 ").value!="Off") items.push(this.getField("Text28").value); if (this.getField("Box29").value!="Off") items.push(this.getField("Text29").value);

// etc.

event.value = items.join("\n");

Likes

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
Most Valuable Participant ,
Apr 17, 2021 Apr 17, 2021

Copy link to clipboard

Copied

How is that different from what you originally had? I thought you wanted to merge them in the order in which the user selects them...

Likes

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 17, 2021 Apr 17, 2021

Copy link to clipboard

Copied

Yep - my mistake! I thought they were coming though in the order selected.  

Likes

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
New Here ,
Apr 17, 2021 Apr 17, 2021

Copy link to clipboard

Copied

I Am Facing Same Issuue If  Anyone Have Soultion Then Tell Me Please 

Likes

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
Most Valuable Participant ,
Apr 17, 2021 Apr 17, 2021

Copy link to clipboard

Copied

You can do it using this function:

 

function mouseUpBox() {
	var summaryTextField = this.getField("Sum1");
	var summary = summaryTextField.valueAsString;
	var textValue = this.getField(event.target.name.replace("Box", "Text")).valueAsString;
	if (event.target.value=="Off") {
		summary = summary.replace(textValue + "\r", "");
		summaryTextField.value = summary;
	} else summaryTextField.value+=textValue+"\r";
}

Add it as a doc-level script, and then call it from the Mouse Up event of each check-box.

Likes

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 17, 2021 Apr 17, 2021

Copy link to clipboard

Copied

LATEST

Excellent - that works perfectly! Thank you - really appreciated.   

Likes

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