Print Page | Close Window

Change field color

Printed From: Foxit's Planet PDF Forum
Category: Lets Talk PDF
Forum Name: JavaScript
Forum Description: Discussions relating to the use of JavaScript within PDF.
URL: http://forums.planetpdf.com/forum_posts.asp?TID=1621
Printed Date: 13 Oct 2019 at 9:51pm
Software Version: Web Wiz Forums 11.10 - http://www.webwizforums.com


Topic: Change field color
Posted By: Maureen
Subject: Change field color
Date Posted: 28 Jul 2015 at 10:02pm
Hello,

Can somebody help me with a javascript for this this: I've a field with a calculation value. If the value is negative  it must shown like -123 in red. Or the color of the field must change in red

Thanks in advanced

Maureen



Replies:
Posted By: try67
Date Posted: 28 Jul 2015 at 11:48pm
You can change the field's color like this:
event.target.textColor = color.red;
Or:
event.target.textColor = color.black;


-------------
- Acrobat Expert - Contact me personally at try6767@gmail.com
Check out my custom-made scripts website: http://try67.blogspot.com


Posted By: Maureen
Date Posted: 29 Jul 2015 at 10:35am
Thanks for your reply, but how can I do it if the field value is negative. So of the field value is a negative value, then the color of the number must change in red. If the value is positive the color stay black


Posted By: try67
Date Posted: 29 Jul 2015 at 10:40am
if (event.value<0) event.target.textColor = color.red;
else event.target.textColor = color.black;

-------------
- Acrobat Expert - Contact me personally at try6767@gmail.com
Check out my custom-made scripts website: http://try67.blogspot.com


Posted By: Maureen
Date Posted: 29 Jul 2015 at 11:55am
It doesn't work :(. Maybe I didn't explane it right. In the simplified field notation I've this calcultion:

field1-field2=field3

I've set your javascript in Custom calculation field. But then it overrules the simplified notation calculation and nothing happens then

What I want in field3 is a script to to this:
field1-field2. If the outcome is a negative value, then the color should be red.
(1-2=-3, so -3 should be in red)

Hope you can help




Posted By: try67
Date Posted: 29 Jul 2015 at 12:51pm
Put it in the custom validation script, then.

-------------
- Acrobat Expert - Contact me personally at try6767@gmail.com
Check out my custom-made scripts website: http://try67.blogspot.com


Posted By: Maureen
Date Posted: 29 Jul 2015 at 2:21pm
still not working :)


Posted By: try67
Date Posted: 29 Jul 2015 at 2:24pm
Works fine for me: https://www.dropbox.com/s/gyobr7j37p2kw4z/Subtraction%20test.pdf?dl=0


-------------
- Acrobat Expert - Contact me personally at try6767@gmail.com
Check out my custom-made scripts website: http://try67.blogspot.com


Posted By: Maureen
Date Posted: 29 Jul 2015 at 2:46pm
I can see yes, Wonder why it's not working for me. What is the exact script you've in the third field?


Posted By: try67
Date Posted: 29 Jul 2015 at 2:51pm
Exactly the same one I gave you... See the field's Validation tab.

-------------
- Acrobat Expert - Contact me personally at try6767@gmail.com
Check out my custom-made scripts website: http://try67.blogspot.com


Posted By: Maureen
Date Posted: 29 Jul 2015 at 3:19pm
In the validation tab I now have:
var v1 = getField("Field1").value;
var v2 = getField("Field2").value;
event.value = v1 - v2;
if (event.value<0) event.target.textColor = color.red;
else event.target.textColor = color.black;

But still not workingCry


Posted By: try67
Date Posted: 29 Jul 2015 at 3:24pm
Move all of that to the custom calculation script, and clear the Validation option.


-------------
- Acrobat Expert - Contact me personally at try6767@gmail.com
Check out my custom-made scripts website: http://try67.blogspot.com


Posted By: BAlheit
Date Posted: 29 Jul 2015 at 3:42pm
Why did you put the calculation in the validation tab?


Posted By: Maureen
Date Posted: 29 Jul 2015 at 4:48pm
YESSS!!! It works. I did all the tabs setting the same as your example and it works!!! Thank you so much for your patience!!!
I'm just a "starter" with this pdf thing, but I like it and it's a form for a charity organisation. So I'm glade to help them out.

Now I want to achieve this:
For example : in fieldA is a value, e.g 180. In FieldB I is also a calculation, but I need to refer to FieldA. So if the value in FieldB is < then FieldA I need the color to change in red.

How can I use your script with the refence in it? It's abou the first part:
if (event.value<0). Instead of <0, what must it be?



Posted By: try67
Date Posted: 29 Jul 2015 at 4:52pm
if (event.value<this.getField("FieldB").value)

-------------
- Acrobat Expert - Contact me personally at try6767@gmail.com
Check out my custom-made scripts website: http://try67.blogspot.com


Posted By: gkaiseril
Date Posted: 29 Jul 2015 at 5:47pm
Validation scripts only execute if the given field is updated. You need to enter a value in another field or clear the field and reenter data.


Posted By: Maureen
Date Posted: 29 Jul 2015 at 6:02pm
your're GOOD!! Thanks again. I had posted another question on this site, and got a reply from you. Just now I've the time to use that script. I will let you know if I can use that script



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.10 - http://www.webwizforums.com
Copyright ©2001-2017 Web Wiz Ltd. - https://www.webwiz.net