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

Simple Help! - Checkbox value to textfield

Explorer ,
Nov 02, 2020 Nov 02, 2020

Copy link to clipboard

Copied

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!

TOPICS
Acrobat SDK and JavaScript

Views

782

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

correct answers 1 Correct answer

Community Expert , Nov 02, 2020 Nov 02, 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 t

...

Votes

Translate

Translate
Community Expert ,
Nov 02, 2020 Nov 02, 2020

Copy link to clipboard

Copied

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

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
Explorer ,
Nov 02, 2020 Nov 02, 2020

Copy link to clipboard

Copied

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

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 ,
Nov 02, 2020 Nov 02, 2020

Copy link to clipboard

Copied

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

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
Explorer ,
Nov 02, 2020 Nov 02, 2020

Copy link to clipboard

Copied

Thank you so much!

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 ,
Nov 02, 2020 Nov 02, 2020

Copy link to clipboard

Copied

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.

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
Explorer ,
Nov 02, 2020 Nov 02, 2020

Copy link to clipboard

Copied

@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!!!

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 ,
Nov 03, 2020 Nov 03, 2020

Copy link to clipboard

Copied

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.

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
Explorer ,
Nov 03, 2020 Nov 03, 2020

Copy link to clipboard

Copied

Thanks Try67! - Man! How do you reply to all these posts? You must type like 300wpm!!! and not sleep! every article I see it has your name on it! - thanks for always helping!!! - I do have 1 issue Im struggling with that I posted in which i think you might be able to help? let me see if i can find the file. Thanks again!

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 ,
Nov 03, 2020 Nov 03, 2020

Copy link to clipboard

Copied

Thanks! (I guess...)

 

Sure, post it and I'll see what I can do.

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
Explorer ,
Nov 03, 2020 Nov 03, 2020

Copy link to clipboard

Copied

It definitely was a compliment! Thank you for your help! ls_rbls has also been helpful, amongst many other members here! I posted it on my forum but I dont know how to provide you the link - I apologize. I also attached screenshots. It should be something basic but maybe not? 

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 ,
Nov 03, 2020 Nov 03, 2020

Copy link to clipboard

Copied

I think what you need is an app.mailMsg script lie shown below:

 

if (event.value !=="") {

app.mailMsg(true);

var cMyMsg = "Hello ";
cMyMsg += event.target.value;

app.mailMsg({
bUI: true,
cTo: "testing@example.net",
cSubject: "This is a test",
cMsg: cMyMsg
} );

}

 

With this script you don't have to worry about the copying and pasting from Acrobat to Outlook,  and also you don't have to manually open Outlook; it will load automatically as soon as the other custom calculation script posts the text string value taken from the "textbox main" fields. 

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
Explorer ,
Nov 03, 2020 Nov 03, 2020

Copy link to clipboard

Copied

That looks and sounds great! Let me try! My only concern is... how will it know when to start and when to stop? I only want it to copy like 5 sentences which include about 10 different text boxes. Hope that makes sense? It would start at "Hello / Good day..." and end at "regards"

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
Explorer ,
Nov 03, 2020 Nov 03, 2020

Copy link to clipboard

Copied

Hi @ls_rbls, I tried this and it worked for opening up my gmail but it never actually loaded the message. Im pretty sure its my error on that end. I wrote a custom javascript on an action (on focus) and then entered the custom code. So when I focused on the button it prepared it but never actually copied any of the message. I wonder what Im doing wrong. Its working nicely but doesnt load? I appreciate your help, I can imagine its been a long day for you and I sincerely appreciate your valuable time and help!

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 ,
Nov 04, 2020 Nov 04, 2020

Copy link to clipboard

Copied

Share the code that you used. 

 

If you noticed I used "event.target.value" in the script because I was trying to run it from the same textfield where the name is populated, I was not using a button.

 

But if you use a button, then you must change event.target.value to "this.getField("textbox main").value" for example.

 

Also, if you notice the variable declared in "cMyMsg" all it does is concatenate the word "Hello " with "this.getField("textbox main").value". But you can put a whole email body here if you want and continue to concatenate with more text strings and other field values.

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
Explorer ,
Nov 04, 2020 Nov 04, 2020

Copy link to clipboard

Copied

LATEST

Good morning! I sent a link to the question and attached the form. Thank you so much for all your time and help! I figured since it was a different question, I didn't want to not have you get credit for any and all help - to include any potential answers. Thank you again!

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 ,
Nov 03, 2020 Nov 03, 2020

Copy link to clipboard

Copied

Just replied...

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