all groups > flash (macromedia) > july 2004 >
You're in the

flash (macromedia)

group:

Submit form on key press: Enter


Submit form on key press: Enter Mattman
7/6/2004 11:52:34 PM
flash (macromedia):
I am building a form in flash, and I want to be able to submit the form when a
user presses the "enter" key. I have a text field for a message, and I want
the form to be able to be submitted when the focus is on the text field and
they press the "enter" key. How can I set this up?
Re: Submit form on key press: Enter Shinchi
7/7/2004 1:47:12 AM
Try something like this?

input is the textfield name

Key.addListener(_root);
var ok = false;
input.onSetFocus = function()
{
ok = true;
}
input.onKillFocus = function()
{
ok = false;
}
onKeyDown = function()
{

if(Key.getCode()==13 && ok)
{
trace("OK!");
}

}
Re: Submit form on key press: Enter Mattman
7/7/2004 2:28:00 AM
Re: Submit form on key press: Enter Mattman
7/7/2004 2:37:08 AM
Actually, I found out why this wasn't working... I had a piece of code that
was:

Selection.setFocus(input);

So, I just modified your code and now I'm using the following which works for
me:

Key.addListener(_root);
onKeyDown = function () {
if (Key.getCode() == 13 && Selection.getFocus() == targetPath(input)) {
goSubmitForm();
}
};
Re: Submit form on key press: Enter Shinchi
7/7/2004 8:23:56 PM
Ok,
Thats great.
AddThis Social Bookmark Button