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

Copy all List Box option to other List box via button at once.

Engaged ,
Jul 01, 2020 Jul 01, 2020

Copy link to clipboard

Copied

I want to achieve something like this :

Document to have 2 list boxes  one filled with options and other empty and along with 1 button (add.)..

I should be able to select multiple option from 1st list box and then press Add button and it will populate all the options from list box1 to list box2 all at once.

 

Currently i have found a file on internet which does the same. but it add 1 option at a time.... when it select multiple options in the 1st listbox.. the add button doesnot work.

 

Plz guide ..

 

Thanks

TOPICS
Acrobat SDK and JavaScript

Views

185

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

Engaged , Sep 18, 2020 Sep 18, 2020

Below Script worked for me :

 

 

var tableSource=new Array();
var selection = this.getField("List Box1").currentValueIndices;
var List1 = this.getField("List Box1");
var List2 = this.getField("List Box2")
if (typeof selection!="object") {
	tableSource.push([List1.getItemAt(selection,false),List1.getItemAt(selection,true)]);
} else {
	for (var i=0; i<selection.length; i++) tableSource.push([List1.getItemAt(selection[i],false),List1.getItemAt(selection[i],true)]);
}
var tableCible=new Array();
var li
...

Likes

Translate

Translate
Community Expert ,
Jul 01, 2020 Jul 01, 2020

Copy link to clipboard

Copied

You can use this code to do it:

var f1 = this.getField("List Box1");
var f2 = this.getField("List Box2");
var selectedItems = f1.value;
if (typeof selectedItems=="object") {
	for (var i in selectedItems) {
		f2.insertItemAt({cName: selectedItems[i], nIdx: -1});
	}
} else f2.insertItemAt({cName: selectedItems, nIdx: -1});

 

Adjust the field names in the first two lines, as needed.

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
Engaged ,
Jul 06, 2020 Jul 06, 2020

Copy link to clipboard

Copied

Thanks this script works but it copies the export value of the first list 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
Engaged ,
Sep 18, 2020 Sep 18, 2020

Copy link to clipboard

Copied

LATEST

Below Script worked for me :

 

 

var tableSource=new Array();
var selection = this.getField("List Box1").currentValueIndices;
var List1 = this.getField("List Box1");
var List2 = this.getField("List Box2")
if (typeof selection!="object") {
	tableSource.push([List1.getItemAt(selection,false),List1.getItemAt(selection,true)]);
} else {
	for (var i=0; i<selection.length; i++) tableSource.push([List1.getItemAt(selection[i],false),List1.getItemAt(selection[i],true)]);
}
var tableCible=new Array();
var listeCible=List2.value;
if (typeof listeCible!="object") {
	tableCible.push([List2.getItemAt(0,false),List2.getItemAt(1,true)]);
} 
tableCible.push([List2.getItemAt(i,false),List2.getItemAt(i,true)]);
}
for (var i=0; i<tableSource.length; i++) {
	var abc = 0;
	for (j=0; j<tableCible.length; j++) {
		if (tableSource[i][0]==tableCible[j][0] && tableSource[i][1]==tableCible[j][1]) {
			abc++;
			break;
		}
		if (abc==0) List2.insertItemAt(tableSource[i][0],tableSource[i][1],-1);
	}
}

 

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