Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Field Validation Max value in Adobe Forms.

New Here ,
Mar 12, 2019 Mar 12, 2019

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.

TOPICS
Acrobat SDK and JavaScript , Windows
734
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 13, 2019 Mar 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 13, 2019 Mar 13, 2019

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 16, 2019 Mar 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 16, 2019 Mar 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

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 16, 2019 Mar 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 16, 2019 Mar 16, 2019

You must use this.getField( ... )

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 17, 2019 Mar 17, 2019

if (KeyAttribute1 == "On"){

if (this.getField(Str).value>this.getField(Lvl).value + 5) {

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

} else if (event.value = this.getField(Str))

} else {

if (this.getField(Str).value>this.getField(Lvl).value + 5)

{

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

} else if(event.value = this.getField(Str))

}

Updated to this, but still getting the same error message. The same section is still showing me a syntax error.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 17, 2019 Mar 17, 2019
LATEST

Why do you if clauses without commands?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 16, 2019 Mar 16, 2019

There are a lot of errors in this code. You might be better off hiring someone to write it for you...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 17, 2019 Mar 17, 2019

It's not that necessary that I would want to hire someone. This is for a side project and if it doesn't work it doesn't work. I just thought I would be able to find guides online here that could help and when I couldn't I thought i could post to the forums for corrections.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines