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

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

928

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 , 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;

Votes

Translate

Translate
Community Expert ,
Mar 11, 2019 Mar 11, 2019

Copy link to clipboard

Copied

Check the console for errors. There are many 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
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

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

Copy link to clipboard

Copied

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

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
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")'

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 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!

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 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.

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 ,
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;

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 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?

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 ,
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.

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 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.

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 ,
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.

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 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

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 ,
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.

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 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

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 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.

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 ,
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.

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 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.

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 ,
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.

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 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

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 ,
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.

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

Copy link to clipboard

Copied

LATEST

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.

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