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

JavaScript on Acrobat

Community Beginner ,
Mar 03, 2023 Mar 03, 2023

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.pngexpand image

Capture d’écran 2023-03-03 à 09.36.14.pngexpand image

Capture d’écran 2023-03-03 à 08.48.07.pngexpand image

after backup

Capture d’écran 2023-03-03 à 09.38.30.pngexpand image

error

Capture d’écran 2023-03-03 à 08.47.44.pngexpand image

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
6.3K
Translate
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
2 ACCEPTED SOLUTIONS
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.

View solution in original post

Translate
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

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

View solution in original post

Translate
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

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.

Translate
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
Can you show me how to do it, because I don't understand where I have to go.
Translate
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

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.

Translate
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

Sans titre-1.jpgexpand image

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?

Translate
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

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

Translate
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

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

Translate
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

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?

Translate
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

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

Translate
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

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

Translate
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

Thanks, I didn't understand while translating.

And for the original problem did you have a solution?

Translate
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

Yes, I already answered that. See above.

Translate
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

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? 😞

Translate
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

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?

Translate
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

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.

Translate
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

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.

Translate
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
Capture d’écran 2023-03-06 à 14.59.04.pngexpand imageCapture d’écran 2023-03-06 à 14.59.16.pngexpand image
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?
Translate
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

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

Translate
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

 

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

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

Translate
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

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

Translate
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
LATEST
thank you so much you are my hero 😄
Translate
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

Where does you use the script?

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

Translate
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