9 Replies Latest reply on Jan 4, 2010 11:59 AM by Ned Murphy

    Automatically move from one text field to another and validate answer in first text field

    rhanna2126

      I'm having a problem that I'd like to see if anyone could help me with.

       

      I have a dynamic text box called help_txt and I have initial instructions to complete the first text field with the applicable information.

       

      Selection.setFocus(prCv1_txt);
      Selection.setSelection(1, 0);

       

      The focus is already set at the beginning of the first text field, which has 2 maximum characters indicated. It is also an input text field.

       

      The correct response for prCv1, which is the variable, is 01.

       

      If the user types 01, I want the following to happen:

      cursor automatically advance to the next text field, which is called groupNo1_txt and I want another message to display in the help_txt field, such as type the correct information in the next field.

       

      If the user does not type 01, I want the following to happen:

      cursor goes back to position 1 of the prCV1_txt text field and another message to display in the help_txt field, such as error, please type 01 in this field.

       

      I originally had the code to verify when the user pressed the Tab key but the error message for the 2nd text box automatically displayed not giving the user the chance to type any information in the second text field (groupNo1_txt).

       

      Can someone please help me!

       

      If you need me to attach a file, I can do so.

       

      Thanks................

        • 1. Re: Automatically move from one text field to another and validate answer in first text field
          Ned Murphy Adobe Community Professional & MVP

          If you can show the code the isn't working for you, someone may be able to determine a solution.

          • 2. Re: Automatically move from one text field to another and validate answer in first text field
            rhanna2126 Level 1

            Selection.setFocus(prCv1_txt);
            Selection.setSelection(1, 0);
            prCv1_txt.tabIndex = 1;
            groupNo1_txt.tabIndex = 2;
            pkgNo1_txt.tabIndex = 3;
            cvlnDate1_txt.tabIndex = 4;
            effRsn1_txt.tabIndex = 5;
            origbneffDt1_txt.tabIndex = 6;
            error_mc._visible = false;

            stop();

            myListener = new Object();
            myListener.onKeyDown = function() {
            if (Key.isDown(Key.TAB) && (prCv1 == "01")) {
              prCv1_txt.textColor = 0x00FF00;
              error_mc._visible = true;
              error_mc.feedback_txt.text = "Type the correct information in the next field. Press Tab when completed.";
            }
            else if (Key.isDown(Key.TAB) && (prCv1 != "01")) {
              prCv1_txt.textColor = 0xFF0000;
              error_mc._visible = true;
              error_mc.feedback_txt.text = "The entry in this field must match the entry in the last benefit line, unless a change from single to family or family to single is being made. Correct this error and press Tab.";
            }
            };
            Key.addListener(myListener);

            myListener = new Object();
            myListener.onKeyDown = function() {
            if (Key.isDown(Key.TAB) && ((groupNo1 == "99999eg5" || groupNo1 == "99999EG5"))) {
              groupNo1_txt.textColor = 0x00FF00;
              error_mc._visible = true;
              error_mc.feedback_txt.text = "Type the correct information in the next field. Press Tab when completed.";
            }
            else if (Key.isDown(Key.TAB) && ((groupNo1 != "99999eg5" || groupNo1 != "99999EG5"))) {
              groupNo1_txt.textColor = 0xFF0000;
              error_mc._visible = true;
              error_mc.feedback_txt.text = "The entry in this field must match the new product's division code. Since this member is changing to EG5, 99999EG5 must be typed in this field. Correct this error and press Tab.";
            }
            }
            Key.addListener(myListener);

            When this code is executed the error message "The entry in this field must match........" displays even before the user can make type anything in the groupNo1_txt field.

            • 3. Re: Automatically move from one text field to another and validate answer in first text field
              Ned Murphy Adobe Community Professional & MVP

              If all that code is in the same frame, then the first half of it is rendered useless by the second half because the same object name is used for the listener and the onKeyDown function.  You may want to rethink the logic of how you manage the processing.

               

              One tool you might consider working in is the onChanged() method of an input textfield.  You can use that to test the entry made in a textfield... for instance, onChanged you can test if the first textfield has 2 characters in it, and if so, test if they equate to "01"... if they do, then you could disable that textfield, and enable the next one and set focus to it. If not, you could reset the textfield or display your error message or whatever.

               

              One recommendation... it appears you might be using the var assigned to the textfields.  Try to avoid that and just test the text property of them instead.  The var end of things can be troublesome.

              • 4. Re: Automatically move from one text field to another and validate answer in first text field
                rhanna2126 Level 1

                Hi,

                Thanks for the information. How do you have the onChanged() method to look for all the information in the text field before verifying the data? When I use it, if there is two digits typed in, it always displays the error message after the first digit is typed.

                • 5. Re: Automatically move from one text field to another and validate answer in first text field
                  Ned Murphy Adobe Community Professional & MVP

                  Use a conditional in the onChanged function that first tests to see if the entry is at least the correct number of characters...

                   

                  if(prCv1_txt.length > 1){

                       if(prCv1_txt.text == "01"){

                            // disable prCv1_txt, enable groupNo1_txt

                       } else {

                            // reset and/or error msg

                       }

                  }

                  • 8. Re: Automatically move from one text field to another and validate answer in first text field
                    rhanna2126 Level 1

                    Sorry to have to ask you another question.

                     

                    In order to access the first text box, which is prCv1_txt, the user must access another frame.

                    When the user accesses the other frame, I add the following code:

                     

                    var visited = "1";

                     

                    So when the user begins to type information into the prCv1_txt field, if they did not visit the other frame, it should display the following message:

                     

                    prCv1_txt.onChanged = function(){
                    if (visited == "1") {
                      error_mc._visible = true;
                      error_mc.feedback_txt.text = "Please type the correct information in the first field. Press the Tab key when completed.";
                    }
                    if (visited != "1") {
                      error_mc._visible = true;
                      error_mc.feedback_txt.text = "Before you make the product change, you need to determine the contract paid-to-date and contract status. Press F3 to identify the contract paid-to-date and the contract status.";
                    }
                    }

                     

                    Now I need to add the code to validate the length of the field and the accuracy of the information the user types in the field. Based on your response, I've revised the code as follows:

                     

                    prCv1_txt.onChanged = function() {
                    if ((prCv1_txt.length > 1) && ((prCv1 == "01"))){
                      prCv1_txt.selectable = false;
                      prCv1_txt.textColor = 0x00FF00;
                      error_mc.feedback_txt.text = "Type the correct information in the next field. Press Tab when completed.";
                    }
                    else if ((prCv1_txt.length > 1) && ((prCv1 != "01"))){
                      prCv1_txt.textColor = 0xFF0000;
                      error_mc.feedback_txt.text = "The entry in this field must match the entry in the last benefit line, unless a change from single to family or family to single is being made. Correct this error and press Tab.";
                    }
                    };

                    I tried to place all four if statements under the same onChanged() function and it did not work correctly. Any suggestions?

                    • 9. Re: Automatically move from one text field to another and validate answer in first text field
                      Ned Murphy Adobe Community Professional & MVP

                      You just need to structure/nest the conditionals based on precedence.  Use an if/else structure to avoid unnecessary testing... Also, if you change to using visited as a Boolean value ( var visited = true; ) you can simplify things a tad.

                       

                      if(visited){

                           if(....length > 1){

                                if(....text == "01"){

                                     // go ahead

                                } else {

                                     // reset/error - wrong entry

                                }

                           }

                      } else {

                           // error - must visit

                      }