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

Validated a Range for a Payment Amount Based on a Checkbox

Explorer ,
Mar 13, 2021 Mar 13, 2021

Copy link to clipboard

Copied

I have a payment page with multiple payment option in an Adobe Acrobat Pro fillable form.

If the payment is by credit card, it cannot be less than $99 or more than $1,849.

If that payment is by check, cash, or money transfer, it cannot be less than $99 or more than $3,598.

I have a script that I wrote (poorly) that works, but also doesn't work (see below).

If the checkbox for the 'other' payment is On, it allows the dollar amount to go up, if it is Off it caps at the right amount.  However, the app.alert pops no matter what is in the field.

Ideally, if the field is cleared or within the range that I've outlined, the app.alert will not display.

I know I'm doing something wrong, left something out, or am looking at this completely incorrectly.  Any guidance would be appreciated.

I have place the following in the Custom Valication Script to run when a user inputs a payment amount.  I selected this because this is where the naturally occuring range validation can be found and it seemed like the logical choice:

if(this.getField("Personal Check").valueAsString != "Off"){
	(event.value <98 || event.value >3599);
	app.alert("Other payments cannot be less than $99 or more than $3,598");
}
else {
	(event.value <98 || event.value >1850);
	app.alert("Credit card payments cannot be less than $99 or more than $1,849");
}

 

TOPICS
Create PDFs , Edit and convert PDFs , How to , JavaScript

Views

1.2K

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 , Mar 13, 2021 Mar 13, 2021

You have to add if before each condition, or combine them using a logical operator. For example:

 

if (this.getField("Personal Check").valueAsString != "Off"){
	if (event.value <98 || event.value >3599) {
		app.alert("Other payments cannot be less than $99 or more than $3,598");
	}
} else if (event.value <98 || event.value >1850) {
	app.alert("Credit card payments cannot be less than $99 or more than $1,849");
}

 

 

 

Votes

Translate

Translate
Community Expert ,
Mar 13, 2021 Mar 13, 2021

Copy link to clipboard

Copied

You have to add if before each condition, or combine them using a logical operator. For example:

 

if (this.getField("Personal Check").valueAsString != "Off"){
	if (event.value <98 || event.value >3599) {
		app.alert("Other payments cannot be less than $99 or more than $3,598");
	}
} else if (event.value <98 || event.value >1850) {
	app.alert("Credit card payments cannot be less than $99 or more than $1,849");
}

 

 

 

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
Explorer ,
Mar 13, 2021 Mar 13, 2021

Copy link to clipboard

Copied

That totally solved it!!!!

You're amazing!  Thank you for answering so quickly.  🙂

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 13, 2021 Mar 13, 2021

Copy link to clipboard

Copied

PS. The two conditions related to event.value will return true even when the field is empty, so you might want to add that as a top-level condition before everything else. Something like this:

 

if (event.value) {

// rest of code
}

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
Explorer ,
Mar 13, 2021 Mar 13, 2021

Copy link to clipboard

Copied

You are my freaking hero!

I had totally accepted that it would just appear if the field was filled in an then cleared.

Thank you so much!

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
Explorer ,
Mar 13, 2021 Mar 13, 2021

Copy link to clipboard

Copied

Okay. I have a new question about this code.

There are multiple options available with Personal Check (Certified Check, Money Order, Cash, Wire Transfer, and Zelle).

When I instruct the code to find these additional checkboxes to follow the instructions that work with Personal Check, the Other Payments direction is bypassed completely and the form views it as....well, I suppose as it should since I'm not instructing it properly.

I've made multiple attempts at an adjustment and none work (see following).  Inclusive of changing all the checkboxes to the same name (Other Payment) with different export values (1-6).

Can you be my hero again?

if (event.value){
if (this.getField("Personal Check").valueAsString != "Off")
if (this.getField("Certified Check").valueAsString != "Off")
if (this.getField("Money Order").valueAsString != "Off")
if (this.getField("Cash").valueAsString != "Off")
if (this.getField("Wire Transfer").valueAsString != "Off")
if (this.getField("Zelle").valueAsString != "Off"){
    if (event.value <98 || event.value >3599) {
    event.value = "";
		app.alert("Other payments cannot be less than $99 or more than $3,598");
	}
} else if (event.value <98 || event.value >1850) {
    event.value = "";
	    app.alert("Credit card payments cannot be less than $99 or more than $1,849");
}
}
if (event.value){
if (this.getField("Personal Check" || "Certified Check" || "Money Order" || "Cash" || "Wire Transfer" || "Zelle").valueAsString != "Off"){
    if (event.value <98 || event.value >3599) {
    event.value = "";
		app.alert("Other payments cannot be less than $99 or more than $3,598");
	}
} else if (event.value <98 || event.value >1850) {
    event.value = "";
	    app.alert("Credit card payments cannot be less than $99 or more than $1,849");
}
}

 

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
Explorer ,
Mar 13, 2021 Mar 13, 2021

Copy link to clipboard

Copied

Additionally, the other hitch with changing the names of the checkboxes was that I was asking it to not check the others if one was selected.  When I tried that with all boxes named the same, it did not work...  Which is part of the reason that I switched back to the specific names.

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 13, 2021 Mar 13, 2021

Copy link to clipboard

Copied

You should give them all the same name, but unique export values, as they are mutually exclusive.

I'm not sure how you want it to work, though... It's better to have a clear description of how it should work, then focus on how to implement it.

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
Explorer ,
Mar 13, 2021 Mar 13, 2021

Copy link to clipboard

Copied

Each checkbox will do the same function:

If selected, they will hide the fields for the credit card payments so nothing can be accidentally filled in - they will trigger the amount field to put a cap on what can be charged (also the same for each box) - they will restrict the selection of any other check box that is categorized as 'other payment'.

Currently, wit the help of your code adjustment above and the other pieces that I've put in place, Personal Check does all of these when selected.

I've attached the page that these are applied to so that you can maybe see better what I mean.  I don't know for sure that I'm explaining it appropriately.

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 13, 2021 Mar 13, 2021

Copy link to clipboard

Copied

I think the original code will work fine if you give all the check-boxes the same name, as I suggested. In that case you'd just need to check that the value is not "Off" (ie. that one of the boxes is ticked), and then perform all of these actions.

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
Explorer ,
Mar 14, 2021 Mar 14, 2021

Copy link to clipboard

Copied

It totally worked!!  I figured out what I was doing wrong.

The visible/hidden code that was here contains a variation(variable...?) "var visible = this.getField("Other Payment").isBoxChecked(0)"

I realized that the 0 applies to the number of the duplicated field.  I was leaving them all as 0 and without the first one selected, the program was doing what it was being told to do.

The explanation was more for me being proud of myself and for anyone reading this later who might be frankencoding something together with cobbled knowledge and guidance.  I know you know this already. Lol

I really appreciate your help with this.  These files have really become powerful devices for me due to your help and your code that restricts printing and saving when required fields are not filled in.

You really have helped me more than you know.  Thank you once again. 🙂

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 14, 2021 Mar 14, 2021

Copy link to clipboard

Copied

One final: less then 98 means less then 98 and not less than 99! So $98 is legal even your text states it shoulb be $99 at least. The same is true for the greater-then-logic.

ABAMBO | Hard- and Software Engineer | Photographer

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
Explorer ,
Mar 14, 2021 Mar 14, 2021

Copy link to clipboard

Copied

LATEST

Thank you!

I caught that too.  But more eyes always helps.

I really do appreciate all the help that I've gotten from this community over the years.

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