Skip to main content
Participant
April 11, 2018
Answered

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

  • April 11, 2018
  • 4 replies
  • 875 views

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 ?

This topic has been closed for replies.
Correct answer try67

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".

4 replies

Edwin_SAuthor
Participant
April 11, 2018

try67, your right.

It works fine now.

Thanks for your quick response !!

Edwin_SAuthor
Participant
April 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.

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
April 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".

Edwin_SAuthor
Participant
April 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.

try67
Community Expert
Community Expert
April 11, 2018

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

try67
Community Expert
Community Expert
April 11, 2018

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

try67
Community Expert
Community Expert
April 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.