4 Replies Latest reply on Nov 18, 2013 5:54 AM by MCDrones

    Populate List Item on Dropdown with first character of Text Field

    MCDrones

      Hello,

       

      I'm trying to create a form where users can enter a credit card number and select the credit card type. I've added a text field for the credit card number and a drop down with the different types (Visa, MasterCard, etc.).

       

      I would like to have the card type triggered by the first digit entered into the text field (All MasterCard numbers begin with 5, so entering 5 would populate MasterCard on the dropdown).

       

      This is my first time creating a PDF, so forgive my lack of knowlege. Any suggestions or help would certainly be appreciated.

       

      Thanks,
      Mike

        • 1. Re: Populate List Item on Dropdown with first character of Text Field
          gkaiseril MVP & Adobe Community Professional

          Do you understand how credit card numbers are assigned and designed to work?

           

          They are for more complex than picking just the first digit. Some will require a 2 digit or 4 digit check and then there is the check digit processing of the number to make sure there has been no transposition or other entry error for the number. Some times the first number indicates the Major Industry Identifier.

           

          The reason many forms ask for the type of card is to force the verification to a specific card type and not trying to guess the card type from the number. If the first digits are entered wrong and one assumes this is a given card type then there is a chance that guess could be wrong.

           

          Bank Card Numbering

          • 2. Re: Populate List Item on Dropdown with first character of Text Field
            MCDrones Level 1

            Thanks for your response GKaiseril. The form I mentioned will be for internal use (5 people). My goal was to save them a step by populating a card type based on the following:

             

            • 3 - travel/entertainment cards (such as American Express and Diners Club)
            • 4 - Visa
            • 5 - MasterCard
            • 6 - Discover Card

             

            Not a huge loss if it can't be done, but I figured it was worth a shot.

             

            Thanks

            • 3. Re: Populate List Item on Dropdown with first character of Text Field
              try67 MVP & Adobe Community Professional

              As suggested, you should be careful when making such assumptions, but it's certainly possible to do it. You can use this code as the custom keystroke event of your text field:

               

              var v = AFMergeChange(event);

              if (v && v.length==1) {

                  if (v.charAt(0)=="5")

                      this.getField("Credit Card Type").value = "MasterCard";

                  else if (v.charAt(0)=="4")

                      this.getField("Credit Card Type").value = "Visa";

                   // etc.       

              }

               

              I've written it in such a way that it will only update when the first digit is entered, so the user can still edit it manually later on, if they wish to.

              • 4. Re: Populate List Item on Dropdown with first character of Text Field
                MCDrones Level 1

                Worked perfectly! Thanks for your help Gilad D.