Highlighted

Need help (javascript)

Community Beginner ,
Aug 24, 2020

Copy link to clipboard

Copied

Hi, I have this code:

If(this.getField("field1").value <5){

event.value = 1000;}

Field1 need to  increase  by 5 (value<10,value<15,value<20...etc)up to 200 and event. value will decrease by 10 every time. Is there a way to do it without making really long code? 

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

You can do it using this code:

 

event.value = 1000 + (Math.floor(Number(this.getField("field1").valueAsString)/5)*10);

TOPICS
Acrobat SDK and JavaScript

Views

56

Likes

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

Need help (javascript)

Community Beginner ,
Aug 24, 2020

Copy link to clipboard

Copied

Hi, I have this code:

If(this.getField("field1").value <5){

event.value = 1000;}

Field1 need to  increase  by 5 (value<10,value<15,value<20...etc)up to 200 and event. value will decrease by 10 every time. Is there a way to do it without making really long code? 

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

You can do it using this code:

 

event.value = 1000 + (Math.floor(Number(this.getField("field1").valueAsString)/5)*10);

TOPICS
Acrobat SDK and JavaScript

Views

57

Likes

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
Aug 24, 2020 0
Most Valuable Participant ,
Aug 24, 2020

Copy link to clipboard

Copied

You can do it using this code:

 

event.value = 1000 + (Math.floor(Number(this.getField("field1").valueAsString)/5)*10);

Likes

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
Reply
Loading...
Aug 24, 2020 1
Adobe Community Professional ,
Aug 24, 2020

Copy link to clipboard

Copied

I was checking out the script and I wasn't able to figure out how to increase all the way up to 200.

 

The user wanted Field1 need to  increase  by 5 (value<10,value<15,value<20...etc)up to 200 "

 

 I'm guessing if it would be convenient to use this script as a custom validation script with a condition to stop the increments when a total value of 200 has been reached?

Likes

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
Reply
Loading...
Aug 24, 2020 0
Engaged ,
Aug 24, 2020

Copy link to clipboard

Copied

There is a "typo" in your code, you need to replace + with -

Likes

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
Reply
Loading...
Aug 24, 2020 0
Blaž LATEST
Community Beginner ,
Aug 25, 2020

Copy link to clipboard

Copied

Thank you try67 for your code and Nesa for tip. 

Likes

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
Reply
Loading...
Aug 25, 2020 0