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

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

Explorer ,
Feb 21, 2019 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!

TOPICS
Acrobat SDK and JavaScript , Windows

Views

257

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
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 21, 2019 Feb 21, 2019

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
Community Expert ,
Feb 21, 2019 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
community guidelines
Explorer ,
Feb 21, 2019 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
community guidelines
Community Expert ,
Feb 21, 2019 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
community guidelines
Explorer ,
Feb 21, 2019 Feb 21, 2019

Copy link to clipboard

Copied

LATEST

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
community guidelines