Skip to main content
Inspiring
July 9, 2021
Answered

copying a result from an optionfield to another

  • July 9, 2021
  • 1 reply
  • 2624 views

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

 

This topic has been closed for replies.
Correct answer try67

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


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

 

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

1 reply

BarlaeDC
Community Expert
July 9, 2021

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.

 

try67
Community Expert
July 9, 2021

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

Inspiring
July 9, 2021

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


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