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

Adding checkboxes with same name but different export values using JS

Participant ,
Apr 02, 2021 Apr 02, 2021

Copy link to clipboard

Copied

Please can someone help me.

I'm trying to add several checkboxes to a page.

All the checkboxes should have the same name but have different export values.

Is this possible as so far I've not succeeded.

Here's the code so far...

thisField = this.getField('dupethis');

var cRtn = app.response("How many checkboxes would you like?");
var prevRect = thisField.rect;
var prevName = thisField.name;
//this.removeField(theFieldName);
var offset = 30;

for (var i = 0; i < cRtn; i++) {
var newRect = [prevRect[0]+offset, prevRect[1], prevRect[2]+offset, prevRect[3]]
var fn = this.addField({
					cName: "p1f1" + "_CB",
					cFieldType: "checkbox",
					nPageNum: 0,
					oCoords: newRect
					});
offset = offset + 30;
var thisExpVal = "sammy" + offset;
fn.exportValues=[thisExpVal];
}


I'm having problems because I'm trying to give all the checkboxes the same name.

I need this so the checkboxes then behave like radio buttons, i.e. only one option can be selected, however with set up the user can uncheck all of the checkboxes.

 

Is this possible? 

Thanks in advance. 

TOPICS
Acrobat SDK and JavaScript , Mac

Views

139

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 Expert ,
Apr 02, 2021 Apr 02, 2021

Copy link to clipboard

Copied

You should apply the export values after having added all of the check-boxes. Try this code:

 

thisField = this.getField('dupethis');

var cRtn = app.response("How many checkboxes would you like?");
var prevRect = thisField.rect;
var prevName = thisField.name;
//this.removeField(theFieldName);
var offset = 30;

var exportVals = [];
for (var i = 0; i < cRtn; i++) {
	var newRect = [prevRect[0]+offset, prevRect[1], prevRect[2]+offset, prevRect[3]]
	this.addField({
		cName: "p1f1_CB",
		cFieldType: "checkbox",
		nPageNum: 0,
		oCoords: newRect
	});
	offset = offset + 30;
	var thisExpVal = "sammy" + offset;
	exportVals.push(thisExpVal);
}
var fn = this.getField("p1f1_CB");
fn.exportValues=exportVals;

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
Participant ,
Apr 02, 2021 Apr 02, 2021

Copy link to clipboard

Copied

Thanks for the speedy help Gilad. 

That works perfectly 🙂

 

Please can I check, rather than referring to the field like this...

thisField = this.getField('dupethis');

 ... is there no way of referring to a 'selected' checkbox when editing in 'Prepare Form'?

 

Thanks again for the help.

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 Expert ,
Apr 02, 2021 Apr 02, 2021

Copy link to clipboard

Copied

No, JS has no access to that info.

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
Participant ,
Apr 02, 2021 Apr 02, 2021

Copy link to clipboard

Copied

LATEST

Thanks for the confirmation.

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