Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

How do I auto fill a Text Box when a Check Box is selected?

Avatar

Level 1

I have 4 check boxes that I would like to auto fill a text box if they are selected.

I am wondering how to do this (as I have never used a script before) and what script should be used?

I am new... so please forgive me as I learn the ropes.

0 Replies

Avatar

Level 1

Have you considered a drop-down menu versus this option?

If the check boxes represent a choice from one question then a drop-down would work.

If the check boxes represent different choice, then they can be independent of each other.

Could you elaborate for better chance of answering your question?

Avatar

Level 1

Thank you for your willingness to help.

The problem with a drop down is that it would not present all options when printed, and some of our users will be completing this form manually (printed). All options need to be displayed.

Here's an example:

SELECT PREFIX:

A12

B12

C12

They can check one of the above and then based on what they select, I want the next box (a text field) to pre-fill with their selection.

So if they select A12, the text box would automatically fill with A12.

Avatar

Level 10

I the change:Event of the drop down box add:

Textfield1.rawValue = xfa.event.newText;

Avatar

Level 1

Thanks for the reply... but per above I am NOT using a drop down.

Avatar

Level 7

Hi,

This is not too difficult.

Checkbox1:Change

if (this.rawValue == "1") {

  this.resolveNode("TextField1").rawValue = "A12";

}

Checkbox2:Change

if (this.rawValue == "1") {

  this.resolveNode("TextField1").rawValue = "B12";

}

ETC

For this purpose, i would consider radio buttons unless your intention is to be able to have multiple items selected. The main problem with checkboxes is that, what do you want to do when they are unchecked? The code above handles when the checkbox is checked but does nothing when unchecked. You would have a situation where you could check multiple boxes but the last one checked would send the value to the textfield.

To handle the uncheck add:

if (this.rawValue == "0") {

  this.resolveNode("TextField1").rawValue = null;

}

This will remove the value from the textfield when the box is unchecked.