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

Need help with a javascript

Community Beginner ,
Mar 11, 2019 Mar 11, 2019

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
1.6K
Translate
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;

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

Check the console for errors. There are many errors.

Translate
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

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

Translate
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

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

Translate
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

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

Translate
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

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!

Translate
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

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.

Translate
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

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;

Translate
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

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?

Translate
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

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.

Translate
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

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.

Translate
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

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.

Translate
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

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

Translate
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

I understood the requirement.

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

Translate
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

The following is present:

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

1:Field:Mouse Up

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

1:Field:Mouse Up

Translate
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

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.

Translate
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

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.

Translate
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

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

Translate
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

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

Translate
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

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

Dropbox - PETS_LoadSheet_2019024-01.pdf

Translate
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

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

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

Translate
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