Skip to main content
Participating Frequently
October 14, 2024
Answered

Overwrite a text box populated based on radio button checking

  • October 14, 2024
  • 1 reply
  • 1496 views

Hi all,

I need help with the following issue in adobe forms:

I have a text box that is auto populated with some text if a radio button is checked. I use a calculation scrip in the text box field and it works fine. The only problem is that a user cannot edit and save the auto filled text.

What should I do?

 

The custom calculation script is somethig like this:

var a = this.getField("radio button").valueAsString;

var text = "text to be populate the text box";

if (a=="Choice1") event.value = text;

else event.value = " ";

This topic has been closed for replies.
Correct answer try67

It works fine for me. The only issue I'm seeing is when you un-check the boxes it doesn't clear the field.


To fix this issue use this code (and yes, it's supposed to be the Calculation script of the text field):

 

if (event.source && (event.source.name=="Checkbox1" || event.source.name=="Checkbox2")) {
	var a = this.getField("Checkbox1").isBoxChecked(0);
	var b = this.getField("Checkbox2").isBoxChecked(0);

	var text1 = "text1";
	var text2 = "text2";

	if (a && b)
		event.value = text1 + text2;
	else if (a)
		event.value = text1;
	else if (b)
		event.value = text2;
	else
		event.value = " ";
}

1 reply

try67
Community Expert
October 14, 2024

Remove that code and place this one as the Mouse Up event of the check-box field (adjust the field name as needed):

 

var a = event.target.value;
var text = "text to be populate the text box";
if (a=="Choice1") this.getField("text field").value = text;
else this.getField("text field").value = " ";
Participating Frequently
October 14, 2024

Thank you! It works, but I also have another question. What should I do if I want to check multiple conditions in order to populate a text box? For example, if two checked buttons are checked, a text should appear in the text box and it should also be editable. Is it possible?

try67
Community Expert
October 14, 2024

That's a bit more complicated. Also, you need to think how it would work, exactly. Should the check-boxes overwrite each value the user entered into the text field, and vice versa?