5 Replies Latest reply on Feb 10, 2015 5:52 PM by flaming1

    Setting a character limit based on a checkbox

    flaming1 Level 2

      Hi

       

      I have a bank form where there is a minimum amount of money required to open a certain type of account.

       

      I currently have a set of checkboxes 'Account Type' that are checked to select the particular type of account. Then the applicant enters the amount they wish to put in to their account in a text field 'Amount $'.

       

      The applicant can put any amount in 'Amount $' unless they check the 'Account Type' box for Term Deposit. Then the amount must be 1000 or more.

       

      I can see how to set a character limit on a field (for four digits), but I need it to only apply if that particular option is checked.

       

      I assume it will be some form of if/else statement:

       

      var one_x=this.getField("Amount $");

      var one_y=this.getField("Account Type");

      if (one_y.value=="Term Deposit") one_x.//this is where I need to tell it to apply a character limit?

      else//tell it not to apply the character limit

       

      Am I on the right track?

       

      Any help is much appreciated.

        • 1. Re: Setting a character limit based on a checkbox
          George_Johnson MVP & Adobe Community Professional

          I don't think the character limit is the right approach since it set the maximum number of characters, not the minimum. You could instead simply look at the entered value. If it's less than 1000 when it should be more, let the user know and reject the value. You can do this with a custom validation script for the $ amount field, something like:

           

          // Custom Validation script for text field

          (function () {

           

              // Allow field to be blank

              if (!event.value) return;

           

              // Reject the value if it's less than 1000

              var acct_type = getField("Account Type").value;

           

              if (acct_type !== "Off" && event.value < 1000) {

                  event.rc = false;

                  app.alert("Please enter a value of 1000 or more.", 3);

              }

           

          })();

          • 2. Re: Setting a character limit based on a checkbox
            flaming1 Level 2

            Thanks George, that approach seems to work, but I still need this to combine with checking which account type they have chosen.

             

            What I don't think I explained very well was that I have a series of five checkboxes - all named 'Account Type', but they return different values.

             

            I only want the warning to trigger if they have checked the box that returns "Term Deposit".

             

            I wonder also if the warning box may worry some people as it is headed up "Warning: Javascript Window". Is there a different type of pop-up that can be used?

             

            Steve

            • 3. Re: Setting a character limit based on a checkbox
              flaming1 Level 2

              I worked out that when I put the value "Term Deposit" into the script, it activates the warning for all the options except that one, so all I had to do was change the '!==' to '==' and it all works beautifully.

               

              Thank you George.

               

              I'd still like to have a less 'threatening' pop-up, but from what I can find that doesn't seem to be an option?

              • 4. Re: Setting a character limit based on a checkbox
                George_Johnson MVP & Adobe Community Professional

                You can't really get rid of that warning message. There are ways, but it requires either that the user installs a JavaScript file on their system or decides to trust PDFs that you've certified.

                 

                An alternative is to use a normally blank text field to display the message, to the right of the input field for example.

                • 5. Re: Setting a character limit based on a checkbox
                  flaming1 Level 2

                  Thanks George. You solved the main issue for me and I really appreciate the help.

                   

                  I'll look into the extra field option too.