Skip to main content
Known Participant
March 11, 2019
Answered

Need help with a javascript

  • March 11, 2019
  • 5 replies
  • 1585 views

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

This topic has been closed for replies.
Correct answer try67

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;

5 replies

Known Participant
March 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

try67
Community Expert
Community Expert
March 11, 2019

I understood the requirement.

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

Known Participant
March 11, 2019

The following is present:

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

1:Field:Mouse Up

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

1:Field:Mouse Up

Known Participant
March 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.

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
March 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;

Known Participant
March 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?

logistics227043683
Known Participant
March 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")'

Known Participant
March 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!

Known Participant
March 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

try67
Community Expert
Community Expert
March 11, 2019

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

Bernd Alheit
Community Expert
Community Expert
March 11, 2019

Check the console for errors. There are many errors.