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

Writing a validation script to javascript......

New Here ,
Apr 11, 2018 Apr 11, 2018

Hi,

I've found a topic about validation of fields.

When a field meet a specific value, the background color changes.

var v = Number(event.value);

if (v>=1 && v<=6) {event.target.fillColor = color.red;}

else event.target.fillColor = color.white;

This is exactly what I want, but I'm using number field with decimals.

How can I check If the value is between 1 and 6.49 and color it red and with all other values, color it white ?

I've tried this, but it didn't work:

var v = Number(event.value);

if (v>=1 && v<=6.49) {event.target.fillColor = color.red;}

else event.target.fillColor = color.white;

Can anyone help me out here ?

TOPICS
Acrobat SDK and JavaScript , Windows
808
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

correct answers 1 Correct answer

Community Expert , Apr 11, 2018 Apr 11, 2018

Actually, because you formatted the fields as using a comma as the decimal separator, you do have to use it...

In addition, you need to disable the fields highlighting to be able to see the colors.

Go to Edit - Preferences - Forms and tick off "Show border hover color for fields".

Translate
Community Expert ,
Apr 11, 2018 Apr 11, 2018

Your code is correct and should work. What happens when you change the value of the field?

Keep in mind the script only executes when you exit the field, not the moment you enter the new 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
New Here ,
Apr 11, 2018 Apr 11, 2018

That's what I thought, but it doesn't work.

When I fill in a whole number (like 1 -6) the background changes to red.

If I fill in 6,4 or 5,2 or 2,2 etc. ect. the background changes to white.

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 ,
Apr 11, 2018 Apr 11, 2018

Can you share the file with us (via Dropbox, Google Drive, Adobe Cloud, etc.)?

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 ,
Apr 11, 2018 Apr 11, 2018

You have to use a period as the decimal separator, not a comma.

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
New Here ,
Apr 11, 2018 Apr 11, 2018

Sorry, that's what I did.

The field is formatted as Number, so I only enter a decimal in the field.

I've uploaded the PDF to Dropbox: Dropbox - Formulier1003.pdf

Please note that this document is in Dutch.

On page 3 I have used the conditional formatting in the 2 columns.

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 ,
Apr 11, 2018 Apr 11, 2018

Actually, because you formatted the fields as using a comma as the decimal separator, you do have to use it...

In addition, you need to disable the fields highlighting to be able to see the colors.

Go to Edit - Preferences - Forms and tick off "Show border hover color for 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
New Here ,
Apr 11, 2018 Apr 11, 2018
LATEST

try67, your right.

It works fine now.

Thanks for your quick response !!

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