Need help with a javascript

Community Beginner ,
Mar 11, 2019 Mar 11, 2019

Copy link to clipboard

Copied

I want to add $3.00 to a field if a checkbox is checked.

If the box is not checked than the original amount entered is not changed.

EFS_FEE is the checkbox name

LUMPER_FEE is the textbox with a value - which could potentially be "0" or any number.

I've tried this and with no luck:

var Lumper = this.getField("LUMPER_FEE")

var Fee = this.getField("EFS_FEE");

if fee.value!="Off"

var Fee = 3

else

var Fee = 0

event.value = Lumper + Fee

TOPICS
Acrobat SDK and JavaScript

Views

298

Likes

translate

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

Most Valuable Participant , Mar 11, 2019 Mar 11, 2019
That's a bit tricky to implement, but try this code as the MouseUp script of the check-box field:var Lumper = this.getField("LUMPER_FEE");if (event.target.value=="Yes") {    Lumper.value = Number(Lumper.value)+3;} else Lumper.value = Number(Lumper.value)-3;

Likes

translate

Translate

Translate
Adobe Community Professional ,
Mar 11, 2019 Mar 11, 2019

Copy link to clipboard

Copied

Check the console for errors. There are many errors.

Likes

translate

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 Beginner ,
Mar 11, 2019 Mar 11, 2019

Copy link to clipboard

Copied

Yeah, the original content, I tried to fix but was not allowed.... latest update - still not working.

var Lumper = this.getField("LUMPER_FEE");

if (this.getField("EFS_FEE").value!="Yes")

var Fee = 3

else

var Fee = 0

event.value = Lumper + Fee

Likes

translate

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
Most Valuable Participant ,
Mar 11, 2019 Mar 11, 2019

Copy link to clipboard

Copied

What's the calculation for this field, without the check-box?

Likes

translate

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
Explorer ,
Mar 11, 2019 Mar 11, 2019

Copy link to clipboard

Copied

I believe you only need to declare variables only once, so take away the "var" in front of, "Fee" and you only need to declare it a variable once. Also, make sure you are using open/closed brackets correctly,  https://www.w3schools.com/jsref/jsref_if.asp like so: if (Fee.value != "Off"){     Fee = 3; } else {     Fee = 0; } Also, make sure that, "Fee" is capitalised since that is how you first declared it, otherwise the script will not work, and put a ';' at the end of, 'var Lumper = this.getField("LUMPER_FEE")'

Likes

translate

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 Beginner ,
Mar 11, 2019 Mar 11, 2019

Copy link to clipboard

Copied

Check re-done code - Original copy was all full error and when I attempted to fix, system locked me out.

Most what you posted already was handled prior to your post. Thanks!

Likes

translate

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 Beginner ,
Mar 11, 2019 Mar 11, 2019

Copy link to clipboard

Copied

There is no calculation for the LUMPER_FEE. It is a hand input value by my drivers. I need to add $3.00 only if a specific case exists.

Likes

translate

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
Most Valuable Participant ,
Mar 11, 2019 Mar 11, 2019

Copy link to clipboard

Copied

That's a bit tricky to implement, but try this code as the MouseUp script of the check-box field:

var Lumper = this.getField("LUMPER_FEE");

if (event.target.value=="Yes") {

    Lumper.value = Number(Lumper.value)+3;

} else Lumper.value = Number(Lumper.value)-3;

Likes

translate

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 Beginner ,
Mar 11, 2019 Mar 11, 2019

Copy link to clipboard

Copied

That does not gonna work. Tried and I'm unclear on 1 thing:

     1: Why are you calling to subtract 3 if the box is not checked?

Likes

translate

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
Most Valuable Participant ,
Mar 11, 2019 Mar 11, 2019

Copy link to clipboard

Copied

Why are you saying it's not going to work before you tried it?

If you want, remove that part of the code and tick and un-tick the box several times and see what happens.

Likes

translate

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 Beginner ,
Mar 11, 2019 Mar 11, 2019

Copy link to clipboard

Copied

Apologize sincerely, I'm typing too darn fast and the meaning, now that I read, was not intended as it sounds.I did not mean I was not going to try it... I meant to say I tried, and it did not work. Too many irons in the fire and responding quickly got me.

Likes

translate

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
Most Valuable Participant ,
Mar 11, 2019 Mar 11, 2019

Copy link to clipboard

Copied

Maybe I misread what you wrote, but to say "it's not working" is not very helpful... What exactly is not working? Is the field not changing when you tick/un-tick the box? Is it changing, but not in the way it should? Be more specific, please.

Likes

translate

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 Beginner ,
Mar 11, 2019 Mar 11, 2019

Copy link to clipboard

Copied

Sorry, When ticking the box no change to the textbox amount occurs.

Current value in the textbox is $120.00

My intended goal (as I am sure you understand) is when the checkbox is ticked the value in the textbox should change to $123.00

Likes

translate

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
Most Valuable Participant ,
Mar 11, 2019 Mar 11, 2019

Copy link to clipboard

Copied

I understood the requirement.

Press Ctrl+J and check if there are any error messages in the Console.

Likes

translate

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 Beginner ,
Mar 11, 2019 Mar 11, 2019

Copy link to clipboard

Copied

The following is present:

TypeError: this.getField(...) is null

1:Field:Mouse Up

TypeError: this.getField(...) is null

1:Field:Mouse Up

Likes

translate

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 Beginner ,
Mar 11, 2019 Mar 11, 2019

Copy link to clipboard

Copied

OK, I figured out why the error on the NULL.. I did not originally have the '_' on the field LUMPER_FEE - just had a space.

However, with that being said, the problem, after correcting the field name, still is present where no change is made to the value on clicking the checkbox.

CTRL-J now shows no error now after field name correction.

Likes

translate

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
Most Valuable Participant ,
Mar 11, 2019 Mar 11, 2019

Copy link to clipboard

Copied

You need to tick the box, then check the Console window again. If it's still not working you'll need to share the file for further help.

Likes

translate

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 Beginner ,
Mar 11, 2019 Mar 11, 2019

Copy link to clipboard

Copied

How do I share the PDF file here? I only see a way to attach an image or HTML.

Likes

translate

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
Most Valuable Participant ,
Mar 11, 2019 Mar 11, 2019

Copy link to clipboard

Copied

You can upload it to something like Dropbox, Google Drive, or the Adobe Document Cloud and then post a link to it here.

Likes

translate

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 Beginner ,
Mar 11, 2019 Mar 11, 2019

Copy link to clipboard

Copied

Hopefully this works. This is a TEST file of what Drivers use in production.

Dropbox - PETS_LoadSheet_2019024-01.pdf

Likes

translate

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
Most Valuable Participant ,
Mar 11, 2019 Mar 11, 2019

Copy link to clipboard

Copied

You've changed the first line of code I've provided and thus rendered it incorrect.

Likes

translate

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 Beginner ,
Mar 11, 2019 Mar 11, 2019

Copy link to clipboard

Copied

Doh, Surely I did. I thought I made no changes. HOWEVER, having said that - that works as you figured.

I elected ot leave the 2nd portion of the code in in case I or the drivers mistakenly check it. Excellent and MANY Thanks.

Likes

translate

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