Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

script/validation question

Not applicable
I have a form with fields called mileage and time, if the person filling in the form misses the field time, and enters a number into the field time, I want a message to pop up saying they need to first enter their mileage (up to 100.0).

I know how to check for the range and make the totals equal no more than the allowed maximums, but I don't know how to make one field dependant on another field.

Suggestions?

Thanks.
10 Replies
Not applicable
Put a validation script on the validate event in time:



if (mileage has a value)

true

else

false
Not applicable
I must be doing something wrong, it's not working - in the Validate section I have -



if (NumericField5)

true

else

false



but it results in an error -

------------

Script failed (language is formcalc; context is xfa[0],form[0],form1[0],#subform[0],#area[4],NumericField3[0])

script=if (NumericField5)

true

else

false

Error: syntax error near token 'true' on line 2, column 8.

------------
Not applicable
Not sure how to do it using FormCalc, try switching to Javascript. And in the if clause you'll want to check the rawValue of NumericField5. It'll be either null or 0 if nothing has been entered, I forget which, but doing that should get it going for you.



H.
Not applicable
Hmm, no luck so far. Here's what I've tried, in javascript mode -

-------------

if (rawValue(NumericField5))

true

else

false

-------------

and also

-------------

if (rawValue(NumericField5==NULL))

true

else

false

------------

I really have no idea what I'm doing. rawValue is not on the drop-down list of functions. Both seem to validate without errors, but there is no effect on the form, like the script is ignored.
Not applicable
Try something like:



if (NumericField5.rawValue==0 || NumericField5.rawValue==null) {

false;

} else {

true;

}



It probably seems like the script is ignored because you don't have teh option turned on in Acrobat to show Javascript errors. In Acrobat go to Edit->Preferences->Javascript and it's call something along the lines of "Show console on errrors".



H.
Not applicable
Thankyou, that works very well. So now I have tried the same script on another field, like this -

-------------

if (NumericField1.rawValue>3 || NumericField3.rawValue>2 || NumericField5.rawValue>100) {

false;

} else {

true;

}

-------------

My intent is to have a field that is optional to begin with become required if any of those 3 fields above have a number greater than the ones shown above. Just for sh#@% & giggles I tried with true; and false; reversed.



But once again, get no response, like it is just ignored (in Preview). I did open Acrobat Pro and check the Preferences/Javascript section, checked the boxes for all the debugger stuff. When I open the doc in Acrobat it gives no errors.
Not applicable
Well the logic of your script is a little off. That says that if any one of those other three fields have values greater than those thresholds then regardless of what is typed into this field it should always fail validation. Something like this may work a bit better:



if ( (NumericField1.rawValue>3 || NumericField3.rawValue>2 || NumericField5.rawValue>100) && (this.rawValue==null || this.rawValue==0) ) }

false;

} else {

true;

}



Don't forget, you can also put xfa.host.messageBox() or app.alert() calls in your script to see which branches of logic they are taking and make debugging easier.



H.
Jodi1725
Level 4
Level 4

I have a similar yet different question.  I want to have a numeric field where you cannot put in a number greater than 4.  So the value in the field can be from 0 to 4 but not greater.  Can I do that with a validation pattern or do I have to add a script to it. and if I do what would it be?

Thanks tons!!!

Jodi

Not applicable
Thankyou for the help, but it still does not seem to work. I don't know how/where to insert the calls you show. I have the form available online if anyone is interested in looking at it - there is also some odd behavior in the validation of two other fields - mileage and travel time. The address is http://www.simradusa.com/b&g%20warranty%20claim%20form.pdf
Not applicable
I have added the alert call to the script and that helps considerably -



if ((LaborTime.rawValue>3 || TravelTime.rawValue>2 || Mileage.rawValue>100) && (this.rawValue==null || this.rawValue==0)) {

false;

app.alert("Please provide your ETP number for full reimbursement.");

} else {

true;

}



But I still have the odd problems with the validation of the TravelTime field.



Any suggestions?