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

Help please with several codes.

Explorer ,
Jul 20, 2020 Jul 20, 2020

Copy link to clipboard

Copied

Happy Monday, 

 

I am still learing and could use a little help please. I searched the previous threads and cannot seem to figure out these several parts of Javascript for my PDF please: 

1) I have the following code in the custom key stroke section: 

"if (event.change) event.rc = /^[a-z]+$/i.test(event.change);"

It's working, but I would like to add a allert/nag pop-up, when someone types a numeric character, please. I can't seem to get that part to work. 

2) I have a section with 5 checkbox choices. I need them to start all as required, but once, one of any of the 5 choices is selected, the required and red outline goes away for the other 4 remaining choices please. 

3) Not sure if this part can be done. If they select specific options in a dropdown, it adds new pages/forms to the bottom of the PDF that have to be completed.

Sorry to be a PITA. Thank you in advance and please stay safe and healthy. 

TOPICS
Acrobat SDK and JavaScript

Views

420

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 20, 2020 Jul 20, 2020

1) Do it like this:

if (!event.rc) app.alert("...");

Votes

Translate

Translate
Participant ,
Jul 20, 2020 Jul 20, 2020

Copy link to clipboard

Copied

1) I have the following code in the custom key stroke section: 

"if (event.change) event.rc = /^[a-z]+$/i.test(event.change);"


try the following code for a popup (the numeral is for the icon on the side ranging from 0 to 3)

 

app.alert("your text here",1);

2) I have a section with 5 checkbox choices. I need them to start all as required, but once, one of any of the 5 choices is selected, the required and red outline goes away for the other 4 remaining choices please. 

 

As long as they're named equally the .value of all the checkboxes will change (thus satisfying the required criteria), otherwise you can change the required status through "fieldobject" .required = 0 / 1  (depending on if its required or not)

 

nb. this.getField("fieldname").required = 1  will set the field to required (although you'll probably want to use the event.target variable in the confirmation tab)

3) Not sure if this part can be done. If they select specific options in a dropdown, it adds new pages/forms to the bottom of the PDF that have to be completed.

 

I havent been able to add pages myself, from what I understand the adding pages requires javascript with special permissions on the computer itself (perhaps someone else has an answer for this)

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 ,
Jul 20, 2020 Jul 20, 2020

Copy link to clipboard

Copied

Thank you for a very very fast reponse! 

1) I added the code and now I get an alert, regardless of what I type in the text box? 

2) I am so confused, when you refer to .value. I thought that meant to name each "Name" under the general tab in this format: Name.0, Name.1, etc. Please explain what I should be doing. 

 

Double thank you in advance.

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 20, 2020 Jul 20, 2020

Copy link to clipboard

Copied

1) Do it like this:

if (!event.rc) app.alert("...");

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 ,
Jul 20, 2020 Jul 20, 2020

Copy link to clipboard

Copied

Danke very much! That fixed # 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
Participant ,
Jul 23, 2020 Jul 23, 2020

Copy link to clipboard

Copied

LATEST

on 2)

 

Lets assume you have 5 checkboxes named: foo , lets say foo#1 has the checkbox value 1 , foo#2 has checkbox value 2 and soforth. In this situation you can only have one of the checkboxes 'checked' at a time.

 

You can get the value of the checked foo box with:  this.getField("foo").value

 

If none of the checkboxes are checked this.getField("foo").value will return off, which will not satisfy the 'required' criteria. However if you select any of the foo boxes the value of this.getField("foo").value will be that of the checked foo box.

 

So checking checkbox foo#2 would return 2 if that was set in the value field of the checkbox.

 

Hope this helps explain things.

 

 

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