Select a Check Box Based on the First Character of a Text Box

Explorer ,
Feb 21, 2019

Copy link to clipboard

Copied

Hello,

I have a form that contains credit card input boxes.  I'm looking for a code that will select the appropriate form of payment based on the first number of the CC number input in the field.

I found this:

this.getField("Check Box").checkThisBox(0, event.value>"0");

Which worked great!  Until I put in the other parameters...then it started selecting multiple check boxes...

Please help!

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Use this code as the custom calculation script of the text field:

this.getField("Visa").checkThisBox(0, (event.value.length>0 && event.value.charAt(0)=="4"));

this.getField("MC").checkThisBox(0, (event.value.length>0 && event.value.charAt(0)=="5"));

etc.

TOPICS
Acrobat SDK and JavaScript, Windows

Views

183

Likes

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

Select a Check Box Based on the First Character of a Text Box

Explorer ,
Feb 21, 2019

Copy link to clipboard

Copied

Hello,

I have a form that contains credit card input boxes.  I'm looking for a code that will select the appropriate form of payment based on the first number of the CC number input in the field.

I found this:

this.getField("Check Box").checkThisBox(0, event.value>"0");

Which worked great!  Until I put in the other parameters...then it started selecting multiple check boxes...

Please help!

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Use this code as the custom calculation script of the text field:

this.getField("Visa").checkThisBox(0, (event.value.length>0 && event.value.charAt(0)=="4"));

this.getField("MC").checkThisBox(0, (event.value.length>0 && event.value.charAt(0)=="5"));

etc.

TOPICS
Acrobat SDK and JavaScript, Windows

Views

184

Likes

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
Feb 21, 2019 0
Most Valuable Participant ,
Feb 21, 2019

Copy link to clipboard

Copied

First of all, that code is not correct. If you're comparing numbers you shouldn't put quotes around them.

Regarding your question: Please describe what you want to achieve in more details, and include the field names of the fields involved.

Likes

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
Reply
Loading...
Feb 21, 2019 1
Explorer ,
Feb 21, 2019

Copy link to clipboard

Copied

There are four check boxes, "Visa", "MC", "Disc", "AmEx".

There is a text field where the 15-16 digit credit card number is to be input, "CC".

What I would like to accomplish is have the corresponding check box be selected automatically based on the first digit of the number input into the CC field.

i.e. if the credit card number start with a 4 then the "Visa" check box is selected. 5 = "MC", 6="Disc", and 3 = "AmEx".

Likes

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
Reply
Loading...
Feb 21, 2019 0
Most Valuable Participant ,
Feb 21, 2019

Copy link to clipboard

Copied

Use this code as the custom calculation script of the text field:

this.getField("Visa").checkThisBox(0, (event.value.length>0 && event.value.charAt(0)=="4"));

this.getField("MC").checkThisBox(0, (event.value.length>0 && event.value.charAt(0)=="5"));

etc.

Likes

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
Reply
Loading...
Feb 21, 2019 2
Explorer ,
Feb 21, 2019

Copy link to clipboard

Copied

YES!  Worked like a charm!!!!

Thank you so much!

Likes

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
Reply
Loading...
Feb 21, 2019 1