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

copying a result from an optionfield to another

Explorer ,
Jul 08, 2021 Jul 08, 2021

Copy link to clipboard

Copied

Hallo,

I am using the following code to transport the result of an optionfield cbox to another named dbox.

(received some help by the community, thank you)

 

this.getField("dBox."+(this.getField("dBox").value-1)).value
=this.getField("cBox."+(this.getField("cBox").value-1)).value;

 

This only works, when i once click into dbox. Then, when clicking into cbox, the result is transported into dbox. If i do not click once into dbox, the result is not transported.

 

I tested dbox.value = "on" in the script, but that did not help

 

I start the form with nothing clicked. See example attached

all the best

Ben

 

TOPICS
Acrobat SDK and JavaScript

Views

190

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

Community Expert , Jul 09, 2021 Jul 09, 2021

Use this code as the Mouse Up script of the cBox fields, then:

 

this.getField("dBox").value = event.target.value;

Likes

Translate

Translate
Community Expert ,
Jul 09, 2021 Jul 09, 2021

Copy link to clipboard

Copied

Hi

 

You have this script -

 

 

event.target.fillColor=this.getField("cBox."+(this.getField("cBox").value-1)).fillColor;
c1=this.getField("cBox."+(this.getField("cBox").value-1)).value;
c2=this.getField("dBox."+(this.getField("dBox").value-1)).value;
event.target.value=10*c1 + c2

 

 

 

No when this form is opened and nothing has been done the value of

 

this.getField("dBox").value is 'Off' and you can't subtract 1 from  a string and get a number that you can use to find the value of a field.

 

You need to add some code in to handle of the checkboxes have not been checked, and decide what you should do in that case.

 

something like

 

 

if ( this.getField("cBox").value != "OFF"){
event.target.fillColor=this.getField("cBox."+(this.getField("cBox").value-1)).fillColor;
c1=this.getField("cBox."+(this.getField("cBox").value-1)).value;
} else {
c1 = 0;
}
if ( this.getField("dBox").value != "OFF"){
c2=this.getField("dBox."+(this.getField("dBox").value-1)).value;
} else {
c2 = 0;
}
event.target.value=10*c1 + c2

 

 

as @try67 mentioned below "OFF" should be "Off", I am unable to edit the code.

 

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 ,
Jul 09, 2021 Jul 09, 2021

Copy link to clipboard

Copied

Small correction: The default value of a check-box (or radio-button) group is "Off", not "OFF"...

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
Explorer ,
Jul 09, 2021 Jul 09, 2021

Copy link to clipboard

Copied

Thank you very much, that helped in the Text-field.

But the radiobutton is stil not working

I added

if ( this.getField("dBox").value = "Off"){
 this.getField("dBox").value = "On";
 }

but that did not work. I stil have to first click the dbox before the copy of the clicks from cbox to dbox works.

hmm...

see attached file

-ben

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 ,
Jul 09, 2021 Jul 09, 2021

Copy link to clipboard

Copied

The comparison operator in JS is "==" (or "==="). Change the first line from:

if ( this.getField("dBox").value = "Off"){

To:

if ( this.getField("dBox").value == "Off"){

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
Explorer ,
Jul 09, 2021 Jul 09, 2021

Copy link to clipboard

Copied

I changed it, buit the result is the same...

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 ,
Jul 09, 2021 Jul 09, 2021

Copy link to clipboard

Copied

Your code doesn't make sense to me. What exactly are you trying to achieve here?

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
Explorer ,
Jul 09, 2021 Jul 09, 2021

Copy link to clipboard

Copied

I try to explain:

 

if i click on cbox, i want dbox to show the same result.

that does not work from the beginning. When i click cbox, nothing happens with dbox.

But: when i once click dbox, than everything works fine. I can click all cbox and the result appears in dbox.

 

I want it to work without first clicking dbox once..

 

I thought, the reason is, that the value of dbox is "Off" in the beginning. Therefore I switched it to "On" if its off

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 ,
Jul 09, 2021 Jul 09, 2021

Copy link to clipboard

Copied

Use this code as the Mouse Up script of the cBox fields, then:

 

this.getField("dBox").value = event.target.value;

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
Explorer ,
Jul 09, 2021 Jul 09, 2021

Copy link to clipboard

Copied

it works. Puh! That easy!  I was thinking too complicated. Thank you

-Ben

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
Explorer ,
Jul 24, 2021 Jul 24, 2021

Copy link to clipboard

Copied

Hi,

i got the things done with your help. I thought, that the pdf also runs on android and ios systems. That was one reason, why I chose pdf.

 

in android, the result of cbox is correctly transferred to dbox, but the result of the addition is always standing at 44 and does not change, when i change the value of cbox. The color is also not changed. This is the code, i added with your help into the calculation region of the textfield.

 

if ( this.getField("cBox").value != "Off"){
event.target.fillColor=this.getField("cBox."+(this.getField("cBox").value-1)).fillColor;
c1=this.getField("cBox."+(this.getField("cBox").value-1)).value;
} else {
c1 = 0;
}
if ( this.getField("dBox").value != "Off"){
c2=this.getField("dBox."+(this.getField("dBox").value-1)).value;
} else {
c2 = 0;
}
event.target.value=10*c1 + c2

Is there a solution that runs under all systems?

Ben

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 ,
Jul 25, 2021 Jul 25, 2021

Copy link to clipboard

Copied

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
Explorer ,
Jul 25, 2021 Jul 25, 2021

Copy link to clipboard

Copied

LATEST

I looked through the supported functions of the api. I have three questions:

- Will the pdf-file also work on a windows laptop, when using the android api?

- at a first look on my sourcecode: I am afraid, that there is no possibility to set a fillcolor then in android?

- Does anybody have a pdf-file with a behaviour coded, that I use in the above file?

all the best

-Ben

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