Skip to main content
Participant
Dec 19, 2022 3:15 PM UTC
Answered

Javascript, checkbox for senior discount on sum

Hello,

 

Im making a fillable form. The user is able to sum theirs costs by entering numbers in text boxes and the total value gets into "Textbox 4".

 

If they are a senior, I want the user to be able to use "Check Box1", and this sum will be multiplied by 0.5 in another box "Final price". If not, I want the sum to be multiplied by 0.1 and get into the box "Final price".

 

Or is there a better way to do simple senior discounts?

 

Much appricieated.

 

 

This topic is closed to new replies. Start a new post to keep the conversation going.
Thom Parker
Thom ParkerCorrect answer
Community Expert
Dec 19, 2022 7:46 PM UTC

First I'd suggest you give the form fields meaningful names.  It'll make scripting and form maintenance easier. 

 

To solve your issue, enter this script into the custom calculation for the "Final Price" field.

 

event.value = this.getField("Textbox 4").value *( (this.getField("Check Box1").value == "Off")?0.1:0.5);

The field names used in the script must exactly match the field names on the form. 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often

7 replies

Participant
Dec 20, 2022 9:10 AM UTC

Is there a better way to do this without the checkbox?

Simply put. I just want the user to be able to see what discount they are getting on their aggregated sum.

Translate
Nesa Nurani
Community Expert
Community Expert
Dec 20, 2022 11:16 AM UTC

Is there other option for users to choose they are seniors other then checkbox?

You can create "Discount" field between "Textbox 4" and "Final Price" and use this script in "Final Price" it will show 10% or 50% if checkbox is checked:

this.getField("Discount").value = this.getField("Check Box1").valueAsString == "Off" ? "10%" : "50%";
event.value = this.getField("Textbox 4").value *( (this.getField("Check Box1").value == "Off")?0.9:0.5);

Translate
Nesa Nurani
Community Expert
Community Expert
Dec 20, 2022 6:00 AM UTC

If checkbox is not checked, you wish to sum remain as in "Textbox 4" ? Because multiply by 0.1 is 90% discount.

Translate
Participant
Dec 20, 2022 8:50 AM UTC

Oh yeah... I wanted to give some discount for non seniors as well. So, then I should do 0.9:05?


If I want 10% of the costs for regulars. 50% for seniors?

 

Thank you for great help

 

Translate
Participant
Dec 20, 2022 8:57 AM UTC

Disregard this.... im bad at math.

Translate
Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
Dec 19, 2022 7:46 PM UTC

First I'd suggest you give the form fields meaningful names.  It'll make scripting and form maintenance easier. 

 

To solve your issue, enter this script into the custom calculation for the "Final Price" field.

 

event.value = this.getField("Textbox 4").value *( (this.getField("Check Box1").value == "Off")?0.1:0.5);

The field names used in the script must exactly match the field names on the form. 

 

 

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
Dec 20, 2022 8:57 AM UTC

If the box is unchecked. It does not do the 10% calculation. For the 10% calculation to be made, I have to check and uncheck the box.

Translate