Highlighted

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

Contributor ,
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

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);
	}
}

 

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

71

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

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

Contributor ,
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

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);
	}
}

 

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

72

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
Jul 01, 2020 0
Most Valuable Participant ,
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
Reply
Loading...
Jul 01, 2020 0
Contributor ,
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
Reply
Loading...
Jul 06, 2020 0
Contributor ,
Sep 18, 2020

Copy link to clipboard

Copied

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
Reply
Loading...
Sep 18, 2020 0