These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Putting a message in a text box based on the value in another box

mark4444az
Registered: Nov 17 2011
Posts: 11

Hi,
I'm trying to print "Fail" in red letters in a text box if the value in another text box is worng.
Here's what I have in the text box wher I want the "Fail" message:
 
var one = this.getField("Text6");
if (one.value != '1234')
{
event.value = "fail";
}
else
{
}
 
this isn't working, and I have no idea how to make the letters red when I get it fixed. Can anyone help?

My Product Information:
Acrobat Pro 9.0, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Doesn't work, how? Is there an error message in the JS console?
To set the text as red just go to that field's properties and change the text color under Appearance.
By the way, you'd probably want to add something like event.value="" in the else-clause, or the "fail" text will stay there forever once it's set.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

mark4444az
Registered: Nov 17 2011
Posts: 11
Well,
Nothing appears in the box. I did add the "", and changed the text color.
mbensch
Registered: Dec 12 2011
Posts: 2
this might not be best practices and i am still super new to js and acrobat. so please correct me if i am wrong.
but why call "event" and not "one"?

one.value = 'fail';
one.textColor = color.red;

also is the field a number? if this is true then couldn't you take out the ' ' around the '1234'
one.value != 1234
Hoyane
Registered: Nov 26 2011
Posts: 33
Your else statement is empty
Text6 is the name of field with number
Code goes in text field you want "Fail" in.

var one = this.getField("Text6");
if (one.value != '1234')
{
event.value = "Fail";
}
else event.value = ""
{
}
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
The "else" can be optional and therefore not required.


George Kaiser

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
The "else" can be optional and therefore not required.


George Kaiser

try67
Expert
Registered: Oct 30 2008
Posts: 2398
That would mean that if the user fills in "1234" and then corrects it to something else, "FAIL" will remain in the text field, but maybe that's what the OP wants to do...

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

mark4444az
Registered: Nov 17 2011
Posts: 11
Still not working at all.
I do have it under the validate tab, maybe that's not the right tab. Here's the code as it is now:
var one = this.getField("Text6");
if (one.value != 1234)
{
event.value = "fail";
}
else
{
"pass"
}
try67
Expert
Registered: Oct 30 2008
Posts: 2398
This is a calculation script, not a validation one. Use this code:

  1. var one = this.getField("Text6");
  2. if (one.valueAsString != "1234") {
  3. event.value = "fail";
  4. }
  5. else {
  6. event.value = "pass";
  7. }

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

mark4444az
Registered: Nov 17 2011
Posts: 11
Ah!! OK, that makes sense. Thanks very much.