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

If anyone can offer advice on how to write javascript to return a 0.......

Participant ,
Jan 05, 2018 Jan 05, 2018

Copy link to clipboard

Copied

If anyone can offer advice on how to write javascript to return a 0 if a number is less than zero I would greatly appreciate it.  I can't seem to figure this out.  Here is the scenario: I'm trying to get field L144 to return a positive number or a zero.  I'm looking at field L26 to make this determination.  I was thinking something along the lines:

var theField = event.value ("L26");

var theValue = theField.value;

if (+theValue > 0) {

    event.value (L144").value = +theValue;

}

else {

     event.value ("L144").value = "0";  

  }

Thank you in advance for any help with this!

TOPICS
Acrobat SDK and JavaScript , Windows

Views

495

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

correct answers 1 Correct answer

Community Expert , Jan 06, 2018 Jan 06, 2018

This is wrong:

event.value ("Ll44").value =

this is correct:

event.value =

Votes

Translate

Translate
Community Expert ,
Jan 05, 2018 Jan 05, 2018

Copy link to clipboard

Copied

Use only event.value = ...

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
Participant ,
Jan 06, 2018 Jan 06, 2018

Copy link to clipboard

Copied

I appreciate your input.  I tried and still no success.  I'm really new at writing Javascript so i'm not in complete understanding how to write code.  I probably haven't written this correctly. 

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
Community Expert ,
Jan 06, 2018 Jan 06, 2018

Copy link to clipboard

Copied

Post your new code, as well as any error messages you're seeing the JS Console.

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
Participant ,
Jan 06, 2018 Jan 06, 2018

Copy link to clipboard

Copied

Here is the code I have currently.  I entered an example that should have returned a positive number and nothing was returned.  I then entered a number that should have been a negative number which returned a 0 but nothing was returned.

var theField = event.value ("L26");

var theValue = theField.value;

if (+theValue > 0) {

    event.value ("Ll44").value = +theValue;

}

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
Community Expert ,
Jan 06, 2018 Jan 06, 2018

Copy link to clipboard

Copied

This is wrong:

event.value ("Ll44").value =

this is correct:

event.value =

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
Community Expert ,
Jan 06, 2018 Jan 06, 2018

Copy link to clipboard

Copied

Your code is still incorrect. Use this:

var theField = this.getField("L26");

var theValue = theField.value;

if (+theValue > 0) {

    event.value = +theValue;

}

By the way, what should be the field's value if it's not bigger than zero? You're currently not applying any other value in that case, so it will stay the same.

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
LEGEND ,
Jan 06, 2018 Jan 06, 2018

Copy link to clipboard

Copied

LATEST

The script goes into the Custom JavaScript calculation for the "L26" field.

One could also add as a first line:

event.value = "";

to clear any entry in the "L26" field.

If you use the key combination "<Ctrl> + J" keys you will open the JavaScript console and should be able to see any syntax errors.

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