Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 631247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:56:39+00:00 2026-05-13T19:56:39+00:00

This is driving me nuts. Its a tough one to explain but I’ll have

  • 0

This is driving me nuts. Its a tough one to explain but I’ll have a go.

I have one input text field on the front page of my site. I have coded a keydown event observer which checks the keyCode and if its ENTER (or equiv), itll check the input value (email). If the email is valid and unique in the DB itll submit the form. Basic stuff, or so you would think.

If I type my email address in the field and hit enter, it works fine in all browsers. However, if I type the first couple of letters, and then use the arrow keys to select the email from the history dropdown box (hope you know what I mean here), and then press enter the result is different. The value of the form field is being captured as just the couple of letters I typed, and therefore the validation is failing. It seems that when I press the enter key to “select” the email from the history dropdown, the browser is interrupting that as if I was typing.

In Chrome and Safari it works as it should. As it should means that when you press enter to “select” the email from the history dropdown, all it does is puts that email address into the text box. Only on the second ENTER key press does it then trigger the event observer, and the email is validated.

Hope somebody can shed some light on why this is happening… My gut feeling is its a browser thing and will be something I cant fix.

Thanks
Lee

EDIT:
To add clarification to my question let me add that Im using the “keydown” event to capture the moment when the enter key is pressed. I have tried the “keyup” event and this solved my problem above, but then I cant seem to stop the form submitting by itself. The “keyup” event triggers AFTER the default behaviour, therefore its not the right choice for this.

FURTHER EDIT:

Thank you again, and btw, your English is excellent (in response to your comment about bad English).

I have changed my event handler from this:

$("emailInputBox").observe("keydown", function(event) {
    return submitViaEnter(event, submitSignupFormOne);
});

to this:

$("emailInputBox").observe("keydown", function(event) {
    setTimeout(submitViaEnter.curry(event, submitSignupFormOne),0);
});

submitViaEnter:

function submitViaEnter(event, callback) {
var code = event.keyCode;
if (code == Event.KEY_RETURN) {
    event.stop();
    return callback(event);
}
return true;
}

Seems to work but the problem now is that the browser is permitted to carry out the default action before running the submitViaEnter function which means the form is being submitted when I hit ENTER.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T19:56:39+00:00Added an answer on May 13, 2026 at 7:56 pm

    Answer to the original question

    Yeah, it’s a Gecko bug (not Mac-specific though).

    The last part of this comment contains the description of the work-around: use the time-out.

    [edit] since you asked for the clarification of the bug

    When you press Enter and the auto-complete is active, Firefox (erroneously) first fires the page’s key handler, then the browser’s internal key handler that closes the autocomplete popup and updates the text area value, while it arguably should just fire it at the autocomplete popup and only let the page know the textbox value changed.

    This means that when your key handler is called, the autocomplete’s handler hasn’t run yet — the autocomplete popup is still open and the textbox value is like it was just before the auto-completion happened.

    When you add a setTimeout call to your key handler you’re saying to the browser “hey, run this function right after you finished doing stuff already in your P1 to-do list”. So the autocomplete’s handler runs, since it’s already in the to-do list, then the code you put on a time-out runs — when the autocomplete popup is already closed and the textbox’s value updated.

    [edit] answering the question in “Further edit”

    Right. You need to cancel the default action in the event handler, not in the timeout, if you want it to work:

    function onKeyPress(ev) {
      if (... enter pressed ...) {
        setTimeout(function() {
          ... check the new textbox value after letting autocomplete work ...
        }, 0);
        // but cancel the default behavior (submitting the form) directly in the event listener
        ev.preventDefault();
        return false;
      }
    }
    

    If you still wanted to submit the form on Enter, it would be a more interesting exercise, but it doesn’t seem you do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This one's got me stumped and it's driving me nuts. I have a SiteFinity
I'm sure this is simple but it's driving me nuts. I have a ListBox
This has been driving me nuts. I hope it's not been asked before but
This is driving me nuts. I believe I asked this exact same question, but
This is driving me nuts. I've looked at all the relevant MSDN tutorials but
Alright, this is driving me nuts because my regex is working on Rubular, but
I have been trying to do this for nearly 3 days now. Its driving
This is driving me nuts. I have a simple spring app with just a
Sorry to post about this, but it's driving me nuts. I am using routes
This one is driving me nuts. The issue only shows up when the datagrid

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.