Hello,
I have a Macromedia Flash MX-based form, and I want to validate the
input to a field. If the validation fails, the invalid text should
become highlighted, and the cursor should be placed in the erroneous
field until the user corrects it.
For example, in the code below, when "first" is not equal to "abc",
then the system should a) select the content of the 'first' text
field, and b) insert the cursor into the 'first' field so that the
user can start typing to correct the invalid input.
Currently, this code WILL do the selection of "first" correctly, but
it will not do the cursor placement correctly. You can see this effect
by going to:
http://www.tufat.com/test.html
You will see a blue textbox and a black textbox. In the black textbox,
type any random string of characters. Then, click the mouse into the
blue textbox. If the contents of the black textbox area not equal to
"abc", then the contents of the black textbox become highlighted, as
they should. However, the *cursor* remains in the blue textbox! I want
the cursor to jump back to the black textbox.
Here's the code.....
createTextField( "first", 2, 10, 10, 200, 20 );
createTextField( "second", 3, 10, 40, 200, 20 );
first.border = 1;
first.borderColor = 0x000000;
first.type = "input";
second.border = 1;
second.borderColor = 0x0000FF;
second.type = "input";
first.onKillFocus = function() {
if ( first.text != "abc" ) {
Selection.setFocus( first );
}
return;
};
Thanks,
Darren
ps. I posted the same question on a FlashKit.com bulletin board, which
you can read here:
http://www.flashkit.com/board/showthread.php?s=a18b3d472ac77d5ed548a6cba480bc4d&threadid=464285
The person who replied to my query didn't really solve my problem,
though. |