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

buttonSetCaption to change based on user input variable

Explorer ,
Jul 21, 2020 Jul 21, 2020

I am currently working on a form that spawns pages and adds the serial number to each page and changes the Button name to the serial number the technician types in.  It works the way I expected, but changing the buttonSetCaption command using a variable also generates an error.  This was liveable but the technicians have requested that we add a way to change the serial number within the document instead of having to create a whole new form. This has become problematic and I can not find a solution online or in any of the forums - any help/insight would be greatly appreciated. Here is the code I have so far:

// If button is Clicked and the hidden check box is not checked - the Analyzer1 check-off pages will be spawned;

var cb2 = this.getField("CB2").value;

// Assign Templates to be spawned a variable so they may be recalled;
var a1a = this.getTemplate("Analyzer1A");
var a1b = this.getTemplate("Analyzer1B");
var a1c = this.getTemplate("Analyzer1C");
var a1d = this.getTemplate("Analyzer1D");

if (cb2 !== "Yes"){

var resp1 = app.response({cQuestion:"Enter The Analyzer Serial Number.", cTitle:"H2S Analyzer Documentation", cLabel:"H2S Analyzer #:"});

if ((resp1 === null)||(resp1 ==="")){

this.getField("Anal1").ButtonSetCaption("Analyzer 1");
}
else{

a1a.spawn({nPage:this.numPages-1,bRename:false,bOverlay:false});
a1b.spawn({nPage:this.numPages-1,bRename:false,bOverlay:false});
a1c.spawn({nPage:this.numPages-1,bRename:false,bOverlay:false});
a1d.spawn({nPage:this.numPages-1,bRename:false,bOverlay:false});

this.getField("CB2").checkThisBox(0,true);

// buttonSetCaption placed at end due to error that stops code from running.  

this.getField("Anal1").buttonSetCaption(resp1).valueAsString;
}}

else{

var nser1 = app.alert ({cMsg:"Documentation For Analyzer 1 Has Already Been Created.\n\n" + "Do you wish to Change the Analyzer Serial Number?",nIcon:2,nType:2 });
// User Pressed Yes
if(nser1 === 4){
var nresp1 = app.response({cQuestion:"Enter The Analyzer Serial Number.", cTitle:"H2S Analyzer Documentation", cLabel:"H2S Analyzer #:"});
nresp1 = resp1;
this.getField("Anal1").buttonSetCaption(resp1).valueAsString;
}
}

TOPICS
Acrobat SDK and JavaScript
588
Translate
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

Explorer , Jul 21, 2020 Jul 21, 2020

Thank You Bernd for the prompt reply. Not sure if I understand - will this allow the caption on the button to be changed to the serial number the technician types in the app.response field without creating an error?

Translate
Community Expert , Jul 21, 2020 Jul 21, 2020

Yes, when you use:

f.buttonSetCaption(resp1);

 

Translate
Community Expert ,
Jul 21, 2020 Jul 21, 2020

Example:

var f = this.getField("myButton");

f.buttonSetCaption("Hello"); 

Translate
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
Explorer ,
Jul 21, 2020 Jul 21, 2020

Thank You Bernd for the prompt reply. Not sure if I understand - will this allow the caption on the button to be changed to the serial number the technician types in the app.response field without creating an error?

Translate
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 ,
Jul 21, 2020 Jul 21, 2020
LATEST

Yes, when you use:

f.buttonSetCaption(resp1);

 

Translate
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