These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Add Radio Button value to Text

sunnymorea
Registered: Mar 2 2011
Posts: 2

Hello Forum,
i try to add a value to a textfield.
i have 3 radio buttons(NGN) with the value 1,2 and 3.
Only one can activate. When the radio button is activate, he must export the value 1 to a textfield (NGN_2). This textfield(NGN_2) is a part of a multiplication. This multiplication have the value 1 (radio button) and a value from an other textfield(NGN1) (for example the value 229 dollar).
I solve this problem with this code:
 
code textfield (NGN_2)
 
event.value = "";
if (this.getField("NBN").value == "1") {
event.value = 1;
}
if (this.getField("NBN").value == "2") {
event.value = 1;
}
if (this.getField("NBN").value == "3") {
event.value = 1;
}
 
but this multiplier (1 from the radio buttons) must edit later manually to an other multiplier.
Everytime i want to edit this multipler, it jumps back to 1.
 
I hope somebody can help me.
thanks al lot
sunny

maxwyss
Registered: Jul 25 2006
Posts: 255
I am not sure, but is it intended that the event.value should be 1 in all three cases?

I guess the code shown is in the Calculate event of the text field. As the Calculate event will happen every time something changes in your form, the value from the NBN field will be read and inserted, annihilating the manually entered value. You can overcome this by "pushing" from the radio button field (instead of "pulling" by the text field. You would add the following code to the MouseUp event of all three instances of the radio button field:

if (event.target.value != "Off") {
this.getField("NGN_2").value = event.target.value*1 ;
} else {
// what to do when the radio button is not checked yet
this.getField("NGN_2").value = 1 ;
// making sure that the calculation does not break down
}

Note that the second part is to make sure that there will be a valid (maybe wrong, but that would have to be adjusted) calculation in the form. You have to know what the default behavior should be.

HTH.

Max Wyss.

sunnymorea
Registered: Mar 2 2011
Posts: 2
Thanks maxwyss,
i solved the problem with this:

var a = this.getField("NGN").value;
var b = this.getField("NGN_2").value;
if(a+b == 1)
event.value = +1; //
else if (a+b == 2)
event.value = +1; //
else if (a+b == 3)
event.value = +1; //

but the only feature now i want is to reset (to 0) the textfield(NGN_2) when the radio buttons are unchecked.

is there a solution?

thanks
sunny