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

JavaScript on Acrobat

Community Beginner ,
Mar 03, 2023 Mar 03, 2023

Copy link to clipboard

Copied

hi everyone,

I need help on Acrobat, I made a script, it works, but when I save it doesn't work anymore.

 

 

my code : 

var checkBox1 = this.getField('companyLogoonsignage');

 

checkBox1.setAction('MouseUp', 'validate(checkBox1, "total2")');

 

function validate(field, formTextField) {

    if (field.isBoxChecked(0)) {

        this.getField(formTextField).value = '80';

    }

    else {

        this.getField(formTextField).value = '0';

    }

}

pose here

Capture d’écran 2023-03-03 à 09.38.45.png

Capture d’écran 2023-03-03 à 09.36.14.png

Capture d’écran 2023-03-03 à 08.48.07.png

after backup

Capture d’écran 2023-03-03 à 09.38.30.png

error

Capture d’écran 2023-03-03 à 08.47.44.png

I have some sort of code compression and it doesn't work anymore so how do I keep my code as it is, if you have any improvements for the code, I take it.

 

sorry for my poor English

TOPICS
JavaScript

Views

5.1K

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 2 Correct answers

Community Expert , Mar 03, 2023 Mar 03, 2023

You should not include the setAction command in your script. This only needs to execute once (if at all), and it won't work in Reader. Also, the "validate" function should be defined either under the field where it's being called, or (better yet) as a doc-level script.

Votes

Translate

Translate
Community Expert , Mar 06, 2023 Mar 06, 2023

Set the field as read-only to block the user from changing its value.

Votes

Translate

Translate
Community Expert ,
Mar 03, 2023 Mar 03, 2023

Copy link to clipboard

Copied

You should not include the setAction command in your script. This only needs to execute once (if at all), and it won't work in Reader. Also, the "validate" function should be defined either under the field where it's being called, or (better yet) as a doc-level script.

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 ,
Mar 03, 2023 Mar 03, 2023

Copy link to clipboard

Copied

Can you show me how to do it, because I don't understand where I have to go.

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 ,
Mar 03, 2023 Mar 03, 2023

Copy link to clipboard

Copied

You'll need to explain first what you're trying to achieve, exactly. What does the check-box has to do with the validation of the "total2" field? If you want the value of the text field to be dependent on that of the check-box use a Calculation script, instead. Then it will execute each time any field in the file (including the check-box) is edited.

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 ,
Mar 06, 2023 Mar 06, 2023

Copy link to clipboard

Copied

Sans titre-1.jpg

So do the final totals no problem: properties > calculation > the value corresponds to/to the sum(+) > checked all the boxes I need

 

I know how to do addition and multiplication, but I don’t know how to block the possibility for a user to change a number field. Do you have any solutions for me?

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 ,
Mar 06, 2023 Mar 06, 2023

Copy link to clipboard

Copied

Set the field as read-only to block the user from changing its 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
Community Beginner ,
Mar 06, 2023 Mar 06, 2023

Copy link to clipboard

Copied

It blocks me all fields me, I need some fields not all.

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 ,
Mar 06, 2023 Mar 06, 2023

Copy link to clipboard

Copied

You need to be more specific. The read-only property applies to each field separately.

What exactly did you do, and what was the result?

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 ,
Mar 06, 2023 Mar 06, 2023

Copy link to clipboard

Copied

so I clicked on lock in the properties and it blocked all the fields, while I want to do as on my document above

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 ,
Mar 06, 2023 Mar 06, 2023

Copy link to clipboard

Copied

Lock and Read-Only are not the same thing. And don't do it for all fields, if you only want to block some...

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 ,
Mar 06, 2023 Mar 06, 2023

Copy link to clipboard

Copied

Thanks, I didn't understand while translating.

And for the original problem did you have a solution?

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 ,
Mar 06, 2023 Mar 06, 2023

Copy link to clipboard

Copied

Yes, I already answered that. See above.

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 ,
Mar 06, 2023 Mar 06, 2023

Copy link to clipboard

Copied

So sorry, I expressed myself badly could you show me an example, because I don't understand sorry, I'm a beginner.

Do you have any screenshots so that I can visually understand how to do it in the software? 😞

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 ,
Mar 06, 2023 Mar 06, 2023

Copy link to clipboard

Copied

Is the purpose of your code simply to populate a text field with "80" if a certain check-box is ticked, and with "0" if it's not ticked? Do you need to apply the exact same code for multiple text fields, just based on different check-boxes, or only for 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
Community Beginner ,
Mar 06, 2023 Mar 06, 2023

Copy link to clipboard

Copied

Overall yes I just want when I check the box at the end of the line in my field it writes 80 and when it doesn't check nothing or 0. And there will be other boxes but not with the same numbers and not the same 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 ,
Mar 06, 2023 Mar 06, 2023

Copy link to clipboard

Copied

You don't need a function for that, or most of the rest of your code, either.

Just use the following as the custom Calculation script of the text field:

 

event.value = (this.getField("Checkbox1").isBoxChecked(0)) ? 80 : 0;

 

Adjust the name of the check-box field in the code as 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
Community Beginner ,
Mar 06, 2023 Mar 06, 2023

Copy link to clipboard

Copied

Capture d’écran 2023-03-06 à 14.59.04.pngCapture d’écran 2023-03-06 à 14.59.16.png
So, thank you, it almost works, there is a weird thing it acts like a subtraction on my final total which is a sum of all the fields at the end of the line, I find it doesn't make sense?

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 ,
Mar 06, 2023 Mar 06, 2023

Copy link to clipboard

Copied

Check the fields calculation order. Make sure the total field is at the end of the list.

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 ,
Mar 06, 2023 Mar 06, 2023

Copy link to clipboard

Copied

 

Capture d’écran 2023-03-06 à 15.42.43.png

This is where it comes into play. Sorry I do not understand

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 ,
Mar 06, 2023 Mar 06, 2023

Copy link to clipboard

Copied

In Prepare Form mode click on More and then on Set Fields Calculation Order.

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 ,
Mar 07, 2023 Mar 07, 2023

Copy link to clipboard

Copied

LATEST
thank you so much you are my hero 😄

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 ,
Mar 03, 2023 Mar 03, 2023

Copy link to clipboard

Copied

Where does you use the script?

Why doesn't you define the function at document level?

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