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

How to ? Checkboxes to fill Textbox in a specific way

New Here ,
Jul 22, 2019 Jul 22, 2019

Copy link to clipboard

Copied

Hello hello everyone,

(First of all, I'm truly sorry for my poor english and thus, for this question badly written, I'm not an english speaker)

(Second, I already tried to find an answer by searching through the forums but I didn't find anything that was of any help with my pretty poor abilities to understand Javascript (and I already asked my question in the french version, which didn't give any result))

Here is the issue I'm facing :

A series of checkboxes whose number associated (I suppose the value?) must be transferred in a text area when checked. Problem “bis”, I don’t understand javascript and the many examples I’ve found on the forum about similar issues, hence I can’t ‘translate” them to my particular situation.

More precise description:

I have a series of checkboxes (in an interactive PDF form that I make with ADOBE ACROBAT PRO), each one represents a certain number "1", "2", "2024", etc. => in fact a code in a list of work risks. The risk "Fall" has the code "1", the "chemical exposure" risk has the risk code "2015", the "screw drilling" risk "14554", etc. etc.

There are about fifteen boxes, each one linked to a risk, therefore to a code.

People can tick these boxes, to say what risks they are exposed to, but I also would like, and this is my concern, to ensure that once the boxes are ticked, the numerical code associated with them is returned in a text box (e.g. Text1), one after the other, in the form of "code#1, code#2, code#3, etc. ».  (So comma+space "code" comma+space "code", etc.)

I know how to create boxes / text field. What I can't do is create the javascript script that makes sure that if I check one box, it goes into the text, that if I check two, no matter which ones, their associated codes go into the text box following each other, and that if I uncheck one check, then its associated code disappears from the text box, without making the data in the other checked boxes disappear.

Intial situation :

Nothing is checkeck ( o ) => Nothing in the textbox

  1. Risk 1                    Code 1                  o
  2. Risk 2                    Code 2                  o
  3. Risk 3                    Code 254              o
  4. Risk 4                    Code 7568            o

Texte :

Situation 1 :

3 boxes are checked (X) => The textbox is automatically field with the code associated to the boxes

  1. Risk 1                    Code 1                  o
  2. Risk 2                    Code 2                  x
  3. Risk 3                    Code 254              x
  4. Risk 4                    Code 7568            x

2, 254, 7568

Te

Sixte :

Situation 1 (bis) :

2 boxes are checked, one was 'un'checked => The textbox automaticaly adapt itself

  1. Risk 1                    Code 1                  o
  2. Risk 2                    Code 2                  x
  3. Risk 3                    Code 254              o
  4. Risk 4                    Code 7568            x

2, 7568

Te

Thank you very much for reading so far.

Olivier

TOPICS
Acrobat SDK and JavaScript , Windows

Views

2.3K

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 , Jul 23, 2019 Jul 23, 2019

I'm noticing now there are errors in the code Bernd provided before. You can use this code instead:

if (this.getField("Checkbox1").valueAsString != "Off") event.value = "1";

else event.value = "";

if (this.getField("Checkbox2").valueAsString != "Off") {

  if (event.value != "") event.value += ", ";

  event.value += "2";

}

However, since you have a lot of check-boxes I would suggest doing it differently.

As the export value of each check-box enter the code for that box, and then you could use this

...

Votes

Translate

Translate
Community Expert ,
Jul 23, 2019 Jul 23, 2019

Copy link to clipboard

Copied

Use a calculation script for the textbox.

Test the checkboxes and add the codes to 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 ,
Jul 23, 2019 Jul 23, 2019

Copy link to clipboard

Copied

Thank you for your very quick answer but it doesn't help me.

I do already understand that I need to add script to my text box and that I have to modify something in my checkbox parameter, but after that, as I said I'm a bit lost.

My skills aren't enough to "write" the code by myself. I don't even grasp the meaning of " event.value" you're referring to. That's why I find it hard to apply the similar solution I've already found on this forum.

Could you give me an example where I could clearly see what part are to be modified by my own data and what part are the code to copypaste?

Knowing that my text field is called "Text1" and that the Checkboxes are all "Checkbox1", "CheckBox2", etc.

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 ,
Jul 23, 2019 Jul 23, 2019

Copy link to clipboard

Copied

Something like this:

if (this.getField("Checkbox1") != "Off") event.value = "1";

else event.value = "";

if (this.getField("Checkbox2") != "Off") {

  if (event.value != "") event.value += ", ";

  event.value += "2";

}

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 ,
Jul 23, 2019 Jul 23, 2019

Copy link to clipboard

Copied

I'm probably too dumb but it doesn't work. When I thick the empty checkboxes (which hence become checked), nothing appears in my textbox field. The information does not pass from one to another.

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 ,
Jul 23, 2019 Jul 23, 2019

Copy link to clipboard

Copied

Press Ctrl+J and check for errors in the JS Console window that opens.

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 ,
Jul 23, 2019 Jul 23, 2019

Copy link to clipboard

Copied

The main issue is that the code I've received doesn't do anything in the way I think it should. And when I try to modify it a bit with my own poor skills it does something that looks like the opposite of my goal .

Isn't it possible to propose another version of this code with an explanation step by step of where, what, how I have to do with Javascript? As I said I don't understand this langage, therefore I can't "see" where it's not right.

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 ,
Jul 23, 2019 Jul 23, 2019

Copy link to clipboard

Copied

Since you don't know JavaScript, as you've said, you should follow the instructions you were given. If it still doesn't work then maybe there's a mistake in the code, or we didn't understand your request correctly, but first you should try it, without changing 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
New Here ,
Jul 23, 2019 Jul 23, 2019

Copy link to clipboard

Copied

I did it, without a change, there were no result whatsoever.

I think that I'm not doing it the right way.

I can try to explain it differently.

I have a textbox (named Textbox1) that is empty and several checkboxes (empty too at first).

I want my textbox to be filled when I thick one or two or... boxes with the "values" or the codes that are associated with.

If I check the first box, the textbox must be populated with 1, if I check the box 1 and the box 15, the textbox must follow : 1, 15

Now after that, if I unchecked the Box 1 and keep the box 15 + add a box 18, a box 19, I want my text box to show automaticaly : 15, 18, 19

It's difficult to make myself understanble in english (that I don't master at all) but it's even more difficult if the subject is complicated I m sorry for that, thanks a lot for helping me despite this issue.

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 ,
Jul 23, 2019 Jul 23, 2019

Copy link to clipboard

Copied

Where did you place the code?

Did you check the JS Console, as I've instructed, after applying the code and clicking the check-boxes?

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 ,
Jul 23, 2019 Jul 23, 2019

Copy link to clipboard

Copied

I place the script into the validation panel of my "text1". When I make the JS Console appear and that I thick on the boxes, nothing happened, anywhere, not in the PDF, not in the console.

Moreover, when I write something in the textbox (eg : 1) it automaticaly filled another ", 2" juste right after in the box and become unmodifiable, undeletable.

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 ,
Jul 23, 2019 Jul 23, 2019

Copy link to clipboard

Copied

Please read the instructions carefully. This is a ​calculation​ script, not a validation one.

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 ,
Jul 23, 2019 Jul 23, 2019

Copy link to clipboard

Copied

My bad, sorry, my Acrobat pro is not in english, I didn't even think about this.

Still, I put the exact copy-paste of the code written by Bernd in the calculation panel (now) and.. still nothing.

I don't think the code is wrong, I think I missed a crucial step somewhere. Maybe that I didn't configurate my checkboxes in the right way?

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 ,
Jul 23, 2019 Jul 23, 2019

Copy link to clipboard

Copied

Now check the JS Console again, or share the file with us, that will be easier...

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 ,
Jul 23, 2019 Jul 23, 2019

Copy link to clipboard

Copied

How can I send you my file ? It will be more easier indeed.

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 ,
Jul 23, 2019 Jul 23, 2019

Copy link to clipboard

Copied

You can email it to me directly via [try6767 at gmail.com] or you can upload it to a file-sharing website (Google Drive, Dropbox, Adobe DC, etc.) and post the link to it here.

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 ,
Jul 23, 2019 Jul 23, 2019

Copy link to clipboard

Copied

I'm noticing now there are errors in the code Bernd provided before. You can use this code instead:

if (this.getField("Checkbox1").valueAsString != "Off") event.value = "1";

else event.value = "";

if (this.getField("Checkbox2").valueAsString != "Off") {

  if (event.value != "") event.value += ", ";

  event.value += "2";

}

However, since you have a lot of check-boxes I would suggest doing it differently.

As the export value of each check-box enter the code for that box, and then you could use this more generic script as the custom calculation script of your text field:

var fields = ["Checkbox1", "Checkbox2"]; // etc.

var selectedCodes = [];

for (var i in fields) {

    var f = this.getField(fields);

    var v = f.valueAsString;

    if (v!="Off") selectedCodes.push(v);

}

event.value = selectedCodes.join(", ");

All you have to do is enter the full list of field names in the first line.

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 ,
Jul 23, 2019 Jul 23, 2019

Copy link to clipboard

Copied

Correct, I forgot the .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 ,
Jul 23, 2019 Jul 23, 2019

Copy link to clipboard

Copied

Thank you very much ! Both of you, Try67 and Bernd, for your patience and for giving me the opportunity to eventually find the way to resolve my issue.

Kind Regards from Belgium !

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 Beginner ,
Dec 19, 2023 Dec 19, 2023

Copy link to clipboard

Copied

LATEST

Hi there! Hoping you can assist me similarly. I have only four check boxes. When each is checked, or multiple are checked, I am trying to have certain pieces of text populate in the text box to provide a brief explainer for the reader. I've been able to code up to the point that when clicking two check boxes, it populates well. I believe I can code for three and four, but for some reason am unable to have the text populate when clicking only one. I have attached the document and hope you can 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 ,
Jul 23, 2019 Jul 23, 2019

Copy link to clipboard

Copied

Why want you validate the text 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