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

problem with calculating total fees and deducting exceptions

Community Beginner ,
Feb 28, 2024 Feb 28, 2024

Copy link to clipboard

Copied

It is quite possible there is a simpler way to do what I am needing help with, but I will describe my issue as best as possible, with how I currently have it, and then explain my issues. I'm not fluent in writing scripts, but if it is explained, I could probably grasp the concept... My querying efforts on this form have not been locating something for me yet.

 

I have a form for requesting rentals and I want it to calculate a total at the end, so the renter knows how much to pay. There are a few variables to throw in though. I have been sucessful at implementing check boxes for the different rooms (4 in total) and having a number associated to each check box which will then add the sum of all check boxes to display at the bottom "Total Rent" text field. I have an additional check box for the entire building which is a different fee, and if I check that box, it will add it to the total. There is a mandatory damage deposit fee for this rental which I currently have a checkbox for.  I have this checkbox automatically checked and is read only, so cannot be unchecked. I have defined the value of this checkbox for the deposit which automatically adds its value to the "Total Rent" text field. Lastly, there is a mandatory fee that gets calculated hourly at $25/hour and there is a minimum charge of $50. Essentially, the first 2 hours are paid by the renter regardless of renting for less than that amount of time. I have two text fields set up right now for this, one for "Hours" and one for "Host Fee". Right now, I have a default value of 2 in "Hours" and I have a calculation set up to calculate a total in the text field "Host Fee" as the value in "Hours" * $25. This will calculate correctly if I change the value in "Hours". As it presents right now, when you open the form, you would see a default "Total Rent" of $350 (deposit + host fee minimum).

 

First issue: I have the additional option to rent the whole building for a different fee (discounted from total of all individual rooms). Can I script something to say "IF" check box "Entire" is checked, it will uncheck boxes "Room1" "Room2" "Room3" and "Room4", and if someone checks one of the individual rooms, it will uncheck "Entire"? This way someone could check off however they wanted with it still calculating the rate correctly. right now, I would have to uncheck the 4 rooms in order to not have them calculate in the total.

 

Second Issue: We have a mandatory fee as mentioned above. This fee does not apply to certain persons, so they are exempt from paying it. Can I set something up whereby I have a checkbox set up with the question "are you exempt from this fee?", call the checkbox "Exempt", and if you check that, it will clear the values from the "Host Fee" so it does not add that calculation into the "Total Rent" text field?

 

Maybe overall there is a better way to implement this whole solution and I am all ears to that!

 

the attachment is just a screenshot of the part of the form I am talking about.

 

Thank you for any help!!!

TOPICS
Acrobat SDK and JavaScript , Windows

Views

1.1K

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 , Feb 28, 2024 Feb 28, 2024

First issue:
use this in "Entire" checkbox as 'Mouse UP' action:

if(event.target.value !== "Off"){
this.getField("Room1").value = "Off";
this.getField("Room2").value = "Off";
this.getField("Room3").value = "Off";
this.getField("Room4").value = "Off";}

Then use this in each of "Room" checkboxes:

if(event.target.value !== "Off")
this.getField("Entire").value = "Off";

Second issue:

Use this in "Exempt" field as 'Mouse UP' action:

if(event.target.value !== "Off")
this.getField("Host Fee").value = "Of
...

Votes

Translate

Translate
Community Expert ,
Feb 28, 2024 Feb 28, 2024

Copy link to clipboard

Copied

First issue:
use this in "Entire" checkbox as 'Mouse UP' action:

if(event.target.value !== "Off"){
this.getField("Room1").value = "Off";
this.getField("Room2").value = "Off";
this.getField("Room3").value = "Off";
this.getField("Room4").value = "Off";}

Then use this in each of "Room" checkboxes:

if(event.target.value !== "Off")
this.getField("Entire").value = "Off";

Second issue:

Use this in "Exempt" field as 'Mouse UP' action:

if(event.target.value !== "Off")
this.getField("Host Fee").value = "Off";

Make sure all field names in scripts are correct, if you have trouble post your actual file with working fields and script you currently use.

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 ,
Feb 29, 2024 Feb 29, 2024

Copy link to clipboard

Copied

Amazing Nesa!

 

Thank you for this. You have saved me significant headache and I really appreciate your 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 01, 2024 Mar 01, 2024

Copy link to clipboard

Copied

I noticed an issue today while playing around with the form.


I cannot change the number of hours in the Host Fee section. It's just resetting back to 2 hours when I come out of the text box.  


is this able to change to any other number?

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 02, 2024 Mar 02, 2024

Copy link to clipboard

Copied

You need to share the file with us so we can see what is going on.

You probably have a calculation script that is changing the value of that field.

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 02, 2024 Mar 02, 2024

Copy link to clipboard

Copied

Here it is. I just removed any unnecessary text. The parts that are relevant for this are all there. 

thank you for taking a look at this!!

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 02, 2024 Mar 02, 2024

Copy link to clipboard

Copied

1. "Host Fee" is a text field not a checkbox, so use this script instead:

if(event.target.value !== "Off")
this.getField("Host Fee").value = 0;

2. As I mentioned in my previous post, you do have a calculation script in "Hours" field that will set the value to 2 if checkbox "Exempt" is not checked, otherwise it will set the value to 0:

event.value = this.getField("Exempt").value == "Off" ? 2 : 0;

What exactly do you want to happen 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 03, 2024 Mar 03, 2024

Copy link to clipboard

Copied

I'll try #1 when I can get to a computer to work on it. 

for #2, what I'm trying to do is display the minimum charge for the host fee when the form opens (which is 2 hours x $25/hour). If it's exempt it drops to $0. If it's not exempt and the person requires more than the minimum charge, I would like them to be able to change the number of hours, and have the calculation be done and added to the total.

For example, renter needs host for 5 hours, so they can enter 5 in the hours and it'll calculate 5 x $25, display that amount in the host fee text field and add it to the total rent. 

Maybe this needs to be completed a different way?

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 03, 2024 Mar 03, 2024

Copy link to clipboard

Copied

Use this script for #2:

if(this.getField("Exempt").valueAsString !== "Off")
event.value = 0;

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 03, 2024 Mar 03, 2024

Copy link to clipboard

Copied

Last question....I hope! 🙂

 

if I check the exempt checkbox, it clears. I can also put any number in there now and it'll calculate. Can I reset the hours back to the default value of 2 if I uncheck the box after?

 

would it be a resetForm code? Under the existing code for exempt? It would be just to reset the hours field. 

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 03, 2024 Mar 03, 2024

Copy link to clipboard

Copied

Yes, reset form for hours field should work for you.

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 04, 2024 Mar 04, 2024

Copy link to clipboard

Copied

I can't figure it out. It'll clear the value when I check the box, but when I uncheck it, the value stays at 0 and doesn't reset back to the default value.

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 04, 2024 Mar 04, 2024

Copy link to clipboard

Copied

LATEST

Use this script instead in "Exempt" checkbox:

if(event.target.value !== "Off")
this.getField("Host Fee").value = 0;
else
this.resetForm(["hours"]);

 

Make sure you have default value set to 2 in "hours" field.

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