JavaScript Troubleshooting

New Here ,
Apr 26, 2019

Copy link to clipboard

Copied

Hi Everyone,

I am an amateur at JavaScript, and hope someone can show me where I am going wrong.

My script is:

event.value = "";

var Text1 = this.getField("Text1").value;

if (Text1!="") {

     if (Number(Text1)>20,Number(Text1)<51) event.value = Number(Text1)-20;

     else if (Number(Text1)>50) event.value = 30

else event.value = 0;

}

Which should:

1. If the input value is under 20, output is zero,

2. If the input value is between 20 and 51, output is input value minus 20

3. If the input value is over 50, output value is 30

It works mostly, however, input values under 20 are giving negatives, not zero.

Where have I gone wrong?

TOPICS
Acrobat SDK and JavaScript

Views

54

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

JavaScript Troubleshooting

New Here ,
Apr 26, 2019

Copy link to clipboard

Copied

Hi Everyone,

I am an amateur at JavaScript, and hope someone can show me where I am going wrong.

My script is:

event.value = "";

var Text1 = this.getField("Text1").value;

if (Text1!="") {

     if (Number(Text1)>20,Number(Text1)<51) event.value = Number(Text1)-20;

     else if (Number(Text1)>50) event.value = 30

else event.value = 0;

}

Which should:

1. If the input value is under 20, output is zero,

2. If the input value is between 20 and 51, output is input value minus 20

3. If the input value is over 50, output value is 30

It works mostly, however, input values under 20 are giving negatives, not zero.

Where have I gone wrong?

TOPICS
Acrobat SDK and JavaScript

Views

55

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
Apr 26, 2019 0
Adobe Community Professional ,
Apr 26, 2019

Copy link to clipboard

Copied

Try this:

event.value = "";

var Text1 = this.getField("Text1").valueAsString;

if (Text1!="") {

    Text1 = Number(Text1);

    if (Text1>20 && Text1<51) event.value = Text1-20;

    else if (Text1>50) event.value = 30;

    else event.value = 0;

}

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...
Apr 26, 2019 2
New Here ,
Apr 26, 2019

Copy link to clipboard

Copied

Great! Thank worked a charm - I'll remember the multiple conditions convention next time

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...
Apr 26, 2019 0