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

Overwrite a text box populated based on radio button checking

New Here ,
Oct 14, 2024 Oct 14, 2024

Copy link to clipboard

Copied

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 = " ";

TOPICS
JavaScript , PDF , PDF forms

Views

355

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
2 ACCEPTED SOLUTIONS
Community Expert ,
Oct 14, 2024 Oct 14, 2024

Copy link to clipboard

Copied

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 = " ";

View solution in original post

Votes

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 ,
Oct 14, 2024 Oct 14, 2024

Copy link to clipboard

Copied

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 = " ";
}

View solution in original post

Votes

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 ,
Oct 14, 2024 Oct 14, 2024

Copy link to clipboard

Copied

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 = " ";

Votes

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
New Here ,
Oct 14, 2024 Oct 14, 2024

Copy link to clipboard

Copied

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?

Votes

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 ,
Oct 14, 2024 Oct 14, 2024

Copy link to clipboard

Copied

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?

Votes

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
New Here ,
Oct 14, 2024 Oct 14, 2024

Copy link to clipboard

Copied

If check box1 is checked the auto populated text box should contain text1.

If check box2 is checked the auto populated text box should contain text2.

If both check box 1 and check box 2, the auto populated text box should contain text 1+ text 2.

 

I have a calculation script in the text field that works fine, but the text cannot be editable.

The calculation script is this one:

var a = this.getField("check box1").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 = " ";

 

Votes

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 ,
Oct 14, 2024 Oct 14, 2024

Copy link to clipboard

Copied

What should happen if the user entered something into the text box, and then changed the values of one of the check-boxes? Should it overwrite what they entered before?

Votes

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
New Here ,
Oct 14, 2024 Oct 14, 2024

Copy link to clipboard

Copied

Yes.

If a user checks both checkboxes, text 3 appears and the user should be able to edit and save it. If, after editing the text, he checks only checkbox 1, then the text box should autopopulate with text 1.

Votes

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 ,
Oct 14, 2024 Oct 14, 2024

Copy link to clipboard

Copied

Then just remove the last line of your code.

Votes

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
New Here ,
Oct 14, 2024 Oct 14, 2024

Copy link to clipboard

Copied

I tried it, but the text edited by the user is not saved when clicking outside the text field. 
I wrote the script as a custom calculation script for the text field. Should I write it somewhere else?

Votes

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 ,
Oct 14, 2024 Oct 14, 2024

Copy link to clipboard

Copied

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

Votes

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 ,
Oct 14, 2024 Oct 14, 2024

Copy link to clipboard

Copied

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 = " ";
}

Votes

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
New Here ,
Oct 14, 2024 Oct 14, 2024

Copy link to clipboard

Copied

LATEST

It works perfectly now, many thanks!! :)))

Votes

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