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

Javascripting Adobe: Adding +1 based off another field?

New Here ,
Apr 20, 2018 Apr 20, 2018

Copy link to clipboard

Copied

So, I'm trying to create a self-calculating form in adobe acrobat to make my life and the lives of others a bit easier (also I've seen other people make them and it looks like a pretty neat skill to have). My problem is I have no idea how to javascript or program, and I need to use javascript to make this form do what I want.

So instead, I've started to teach myself the basics of javascript to create calculating forms, but I've gotten stuck on a couple of fields that I'm not sure how to solve. So here's my code so far:

var mf = this.getField("field1") ;

if (mf.value > 0 && mf.value < 8) {

event.target.value = [+0] ;

} else {

if (mf.value >= 8 && mf.value ) {

event.target.value = [+1] ;

} else {

event.target.value = [+0] ;

}

}

What I want this calculating form to do is: When a user inputs a number of 8 or more in field1, then field2 gets a +1. Just once. If field1 goes below 8, the +1 in field2 goes away. So tried to implement that. One time, field2 started adding +1 every time field1 is updated (really?) or it'll reset field2 to 1 if field1 is ever changed (just No).

I think what I really need at this point is some outside help from someone who knows how this stuff works. Is there anyone who could tell me what I'm doing wrong?

TOPICS
Acrobat SDK and JavaScript , Windows

Views

283

Translate

Translate

Report

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 ,
Apr 20, 2018 Apr 20, 2018

Copy link to clipboard

Copied

Want you display "+1" or add 1 to the value in the field?

Votes

Translate

Translate

Report

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 ,
Apr 21, 2018 Apr 21, 2018

Copy link to clipboard

Copied

Just add 1 to the value of the field. And only once; The 1 is supposed to go away if field1 ever falls below 8.

The 1 is supposed to be a bonus; it's added to whatever the user inputs in field2. For example, the user puts in a number for field2. If field1 is 8 or more, then field2 is going to be "whatever the user put in there, plus 1" and "if field1 is 7 or less, then leave field2 unchanged." if that makes sense.

I don't think I learned the scripting language that says "just add 1 to this field" but I don't know what that would be.

Votes

Translate

Translate

Report

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
Engaged ,
Apr 30, 2018 Apr 30, 2018

Copy link to clipboard

Copied

LATEST

var mf = this.getField("field1") ;

if (mf.value > 8)  event.target.value++ //increments value (+1)

//You can see that I did not use brackets  { } because when your (if statement) only as one command afterward, you don't need to put it in brackets

But since you increment the value in field2, it will increment that value each time you change the value of field1 to a number grater than 8.  For exemple, if the user sets field2 to 1 and sets field1 to 22, it will update field2 with the +1 increment.  Then, if you change field1 to 33, it will add another increment.  To prevent this from happening, you must not increment the value of field2 but increment what field2 is populated from, then assign the total to field2.

var mf = this.getField("field1")

var total = //some data

if (mf.value > 8)  total++ //increments value (+1)

event.target.value = total

and just FYI, if you would want to increment to more than 1, use the += operator as in:

if (mf.value > 8)  total += 5 //this means total = total + 5

Votes

Translate

Translate

Report

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