Skip to main content
ezloves2smile
Known Participant
November 3, 2020
Answered

Simple Help! - Checkbox value to textfield

  • November 3, 2020
  • 3 replies
  • 1924 views

Hello, I have something that may be simple to most of you but difficult for me. That being said, please forgive my ignorance and thank you in advance for your valuable help! I have a form where lets say there are 3 text fields with names. Let's call them: "name1, name2, name3" and in those 3 text fields you can add a name. Let's say: "John, Jamie, Bob" (name1 = John) (name2 = Jamie) (name3 = Bob). Now let's say I have a check box next to each text field (cb1, cb2, cb3 - checkbox1, 2, 3). So now let's say I have "textbox main" and let's say I click a value of "off and on" for each checkbox. If I default cb1 for "John" or "name1" then it will appear on "textbox main". If i click on "cb2" or in this case "Jamie" or "name2" then it will appear on "textbox main". Finally if i click on cb3 or checkbox 3 for "Bob" or "name3" then again, it will appear on "textbox main". Does that make sense? Thank you for your time and help and hopefully someone out there can help!

This topic has been closed for replies.
Correct answer ls_rbls

There are many ways to accomplish this with JavaScript scripting.

 

In my personal case, I named all checkboxes as "cb" but changed their export values to "cb1", "cb2", and "cb3" respectively to make them mutually exclusive. Making these checkboxes mutually exclusive will make the checkboxes behave like a radio button by which a single selection is made out of the three checkboxes.

 

This is to avoid "textbox main" field from autopopulating all the values in name1, name2, and /or name3 if more than one checkbox  was checked.   

 

Then I  used a custom calculation script in the "textbox main" field like this:

 

event.value ="";

if (this.getField("cb").value=="cb1") {event.value = (this.getField("cb").isBoxChecked(0)) ? this.getField("name1").value : event.value=""; }

if (this.getField("cb").value=="cb2") {event.value = (this.getField("cb").isBoxChecked(1)) ? this.getField("name2").value : event.value=""; }

if (this.getField("cb").value=="cb3") {event.value = (this.getField("cb").isBoxChecked(2)) ? this.getField("name3").value : event.value=""; }

 

NOTE: This works for me but I am getting an error in the debugger console.I tried many different scripts but still end up getting this error:

 

1:Field:Calculate
SyntaxError: missing ; before statement

 

Hopefully someone can share additional insights about this error and point me in the right direction. 

 

In the meanwhile you can use the script above and test it or modify it.

3 replies

ls_rbls
ls_rblsCorrect answer
Adobe Expert
November 3, 2020

There are many ways to accomplish this with JavaScript scripting.

 

In my personal case, I named all checkboxes as "cb" but changed their export values to "cb1", "cb2", and "cb3" respectively to make them mutually exclusive. Making these checkboxes mutually exclusive will make the checkboxes behave like a radio button by which a single selection is made out of the three checkboxes.

 

This is to avoid "textbox main" field from autopopulating all the values in name1, name2, and /or name3 if more than one checkbox  was checked.   

 

Then I  used a custom calculation script in the "textbox main" field like this:

 

event.value ="";

if (this.getField("cb").value=="cb1") {event.value = (this.getField("cb").isBoxChecked(0)) ? this.getField("name1").value : event.value=""; }

if (this.getField("cb").value=="cb2") {event.value = (this.getField("cb").isBoxChecked(1)) ? this.getField("name2").value : event.value=""; }

if (this.getField("cb").value=="cb3") {event.value = (this.getField("cb").isBoxChecked(2)) ? this.getField("name3").value : event.value=""; }

 

NOTE: This works for me but I am getting an error in the debugger console.I tried many different scripts but still end up getting this error:

 

1:Field:Calculate
SyntaxError: missing ; before statement

 

Hopefully someone can share additional insights about this error and point me in the right direction. 

 

In the meanwhile you can use the script above and test it or modify it.

ezloves2smile
Known Participant
November 3, 2020

@ls_rbls  - YOU... ARE... AWESOME!!! It works perfect! Your code worked like a charm and all it needed was a semi colon before your statement:

 

;event.value ="";

if (this.getField("cb").value=="cb1") {event.value = (this.getField("cb").isBoxChecked(0)) ? this.getField("textbox main").value : event.value=""; }

if (this.getField("cb").value=="cb2") {event.value = (this.getField("cb").isBoxChecked(1)) ? this.getField("textbox main2").value : event.value=""; }

if (this.getField("cb").value=="cb3") {event.value = (this.getField("cb").isBoxChecked(2)) ? this.getField("texbox main3").value : event.value=""; }

 

Thank you so very much for the prompt and efficient reply! I dont think Ive ever had anyone explain it and break it down the way you have, you should probably do videos for people like me who need a bit more clarification and understanding. Thank you, thank you, thank you!!!

try67
Adobe Expert
November 3, 2020

Ah no, that is not necessary. Maybe there was an issue with how you entered it, but a semi-colon at the start of the code is not needed.

ezloves2smile
Known Participant
November 3, 2020

My apologies, this would be in Adobe DC - custom script sections? and or validate fields?

jane-e
Adobe Expert
November 3, 2020

I edited your post to add tags for Forms and JavaScript so the right folks might find it.

 

Just for an FYI, Adobe is a company that makes a lot of software. This application is Adobe Acrobat DC, which comes in Pro and Standard (plus the free Reader).

 

~ Jane

ezloves2smile
Known Participant
November 3, 2020

Thank you so much!

John T Smith
Adobe Expert
November 3, 2020

Please post the exact name of the Adobe program you use so a Moderator may move this message to that forum