Skip to main content
Participating Frequently
March 13, 2019
Question

Field Validation Max value in Adobe Forms.

  • March 13, 2019
  • 3 replies
  • 678 views

I was trying to mess around with maximum values within the fields of my Adobe Form document.

I learned how to do this through the validation tab in the text field properties, but I was trying to set it so that the maximum value for that field would be based on the value of another field and the checking of a check box.

So for instance...

Field1 is titled Lvl

Field2 is titled Str

Checkbox is titled KeyAttribute1

Str would have a maximum value of Lvl+2, and if a value higher than that would be entered text would appear that would say "Strength cannot be higher than your level + 2". Alternatively, if KeyAttribute1 were selected it would change the maximum value and the text would change to be Lvl+5, rather than Lvl+2.  

I have read things that show me this is possible, but I cant seem to figure out how to make it work. My best guess is something along these lines...

var direction;

if(get.thisField("Str").value>get.thisField("Lvl").value + 2)

else ("Strength cannot be higher than your level + 2")

if(KeyAttribute1 == “Off” )

{

var direction;

if(get.thisField("Str").value>get.thisField("Lvl").value + 5)

else ("Strength cannot be higher than your level + 5")

}

But it won't even let me enter this because it says everything between the brackets is a syntax error. There are some other max field formulas I wanted to do, but they don't involve checkboxes, so I feel that if I figure out how to do this, the others will be easier.

This topic has been closed for replies.

3 replies

Participating Frequently
March 16, 2019

I updated it to read as such. It still will not accept it. It reads "SyntaxError: syntax error 1; at line 2"

if (KeyAttribute1 == "On") (if(get.thisField("Str").value>get.thisField("Lvl").value + 5) (event.value = app.alert ("Strength cannot be higher than your level + 5"))else(event.value = get.thisField("Str)))

else (if(get.thisField("Str").value>get.thisField("Lvl").value + 2) (event.value = app.alert ("Strength cannot be higher than your level + 2"))else(event.value = get.thisField("Str)

Thank you for the help so far.

try67
Community Expert
Community Expert
March 16, 2019

You need to study the core syntax of JavaScript. After an if-statement there should be curly brackets with the code associated with it in them, like this:

if (condition) {

   // code to execute if condition is true

} else if (other condition) {

   // code to execute if other condition is true

} else {

   // code to execute if neither conditions are true

}

Participating Frequently
March 16, 2019

Okay. So I have this now.

if (KeyAttribute1 == "On") {

if (get.thisField("Str").value>get.thisField("Lvl").value + 5) {

event.value = app.alert ("Strength cannot be higher than your level + 5")

} else if (event.value = get.thisField("Str"))

} else {

if (get.thisField("Str").value>get.thisField("Lvl").value + 5)

{

event.value = app.alert ("Strength cannot be higher than your level + 2")

} else if(event.value = get.thisField("Str"))

}

The bolded section is not actually bolded, but it is the section it is highlighting and saying syntax error.

I massively appreciate your help as it is helping me to actually learn this, and has given me some guidance with looking stuff up. The syntax error I'm getting now has me stuck though.

Bernd Alheit
Community Expert
Community Expert
March 13, 2019

When you want display a message use something like app.alert("hello");

try67
Community Expert
Community Expert
March 13, 2019

- You have to only use straight quotes, not curly ones. Do NOT use Word for writing code, if that's what you're doing.

- You must include some kind of command to execute after the if-statement and before the else-statement.