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
Use this code as the Mouse Up script of the cBox fields, then:
this.getField("dBox").value = event.target.value;
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.
Copy link to clipboard
Copied
Small correction: The default value of a check-box (or radio-button) group is "Off", not "OFF"...
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
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"){
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Your code doesn't make sense to me. What exactly are you trying to achieve here?
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
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;
Copy link to clipboard
Copied
it works. Puh! That easy! I was thinking too complicated. Thank you
-Ben
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
Copy link to clipboard
Copied
Acrobat Reader on Android does support this:
https://www.adobe.com/devnet-docs/acrobatetk/tools/Mobile/androidapi/index.html
Copy link to clipboard
Copied
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