Copy link to clipboard
Copied
Hello,
I have a form that a user will select if a specific item is for a member or non member (with associated price discount for members). They also have to enter a Quantity. There is then a total amount field that gets automatically calculated. I have part of this working but would like the Total amount field to go back to being null if the user unchecks the Quantity and Member or Nonmember checkbox. Here is the code that I currently have:
if (this.getField("511 Digital Access Code Ckbx").valueAsString == "No") event.value=(this.getField("511 Digital Access Code Qty").value * 40);
if (this.getField("511 Digital Access Code Ckbx").valueAsString == "Yes") event.value=(this.getField("511 Digital Access Code Qty").value * 20);
if (this.getField("511 Digital Access Code Qty").value == null) event.value=(this.getField("511 Digital Access Code Total").value == null);
if (this.getField("511 Digital Access Code Qty").rawValue.length == 0) event.value=(this.getField("511 Digital Access Code Total").value == null);
example of issue. User selects member pricing ($20) for an item with the Quanity of 5 . The Total field calculates to $100. That all works fine. If they unselect the checkbox and clear out the Quantity field, I still have a total of $100 in the Total field.
1 Correct answer
If you were able to review the little script that I shared in the link above, you will notice that I'm not using "Yes" and "No" to set the condition that I used in the calculation script.
You need to use "Yes" and/or "Off" instead of "Yes" and/or "No" to reflect the correct operation in your calculation when the checkbox is ticked or un-ticked.
If you want to see for yourself create really quick a text field, and add a custom calculation script like this:
event.value = this.getField(""511 Di
...
Copy link to clipboard
Copied
Hi,
Just yesterday I shared with another user a little script that just do exactly the opposite, but you can modify it to suite your script action.
You can review it here:
Copy link to clipboard
Copied
If you were able to review the little script that I shared in the link above, you will notice that I'm not using "Yes" and "No" to set the condition that I used in the calculation script.
You need to use "Yes" and/or "Off" instead of "Yes" and/or "No" to reflect the correct operation in your calculation when the checkbox is ticked or un-ticked.
If you want to see for yourself create really quick a text field, and add a custom calculation script like this:
event.value = this.getField(""511 Digital Access Code Ckbx").value;
Try the following code for your custom calculation script of the "511 Digital Access Code Total" field:
if (this.getField("511 Digital Access Code Ckbx").value == "Off") event.value=(this.getField("511 Digital Access Code Qty").value * 40);
if (this.getField("511 Digital Access Code Ckbx").value == "Yes") event.value=(this.getField("511 Digital Access Code Qty").value * 20);
if (this.getField("511 Digital Access Code Qty").value =="") event.value ="";
Copy link to clipboard
Copied
That worked perfectly. Thanks for your help.
Copy link to clipboard
Copied
You're welcome. Happy to help.
Don't forget to mark this solution as correct, so that other users with similar issues can find the answer quickly in the forums
Copy link to clipboard
Copied
The value of a check-box can't be blank, so the last line is not needed.
Copy link to clipboard
Copied
Hi Try67,
I'm confused, the last line in the above code was not meant to be used as a javascript mouse up action of the checkbox field.
This code was meant to be used as custon calculation script of the Total field.
The last line event.value=""; is to trigger a null (empty blank) result in this field if the user doesn't type in anything in the Quantity field.
c
Copy link to clipboard
Copied
Sorry, I misread the field name.
At any rate, if it's a calculation script you should use event.value = ..., not this.getField("").value = ...
Copy link to clipboard
Copied
got it.
thank you so much. as usual

