-
1. Re: Automatically move from one text field to another and validate answer in first text field
Ned Murphy Jan 4, 2010 7:15 AM (in response to rhanna2126)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 Jan 4, 2010 7:42 AM (in response to Ned Murphy)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.
-
test.fla.zip 5.3 K
-
-
3. Re: Automatically move from one text field to another and validate answer in first text field
Ned Murphy Jan 4, 2010 8:18 AM (in response to rhanna2126)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 Jan 4, 2010 8:37 AM (in response to Ned Murphy)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 Jan 4, 2010 8:57 AM (in response to rhanna2126)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
}
}
-
6. Re: Automatically move from one text field to another and validate answer in first text field
rhanna2126 Jan 4, 2010 9:13 AM (in response to Ned Murphy)Thank you very much!
Robert.
-
7. Re: Automatically move from one text field to another and validate answer in first text field
Ned Murphy Jan 4, 2010 9:16 AM (in response to rhanna2126)You're welcome
-
8. Re: Automatically move from one text field to another and validate answer in first text field
rhanna2126 Jan 4, 2010 9:43 AM (in response to Ned Murphy)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 Jan 4, 2010 11:59 AM (in response to rhanna2126)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
}