Skip to main content
ZombieLuna
Inspiring
February 21, 2019
Answered

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

  • February 21, 2019
  • 1 reply
  • 1004 views

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!

This topic has been closed for replies.
Correct answer try67

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.

1 reply

try67
Community Expert
Community Expert
February 21, 2019

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.

ZombieLuna
Inspiring
February 21, 2019

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".

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
February 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.