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 7397871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:48:07+00:00 2026-05-29T03:48:07+00:00

I wrote a js and it look like $(‘#searchform’).keydown( function( event ) { if

  • 0

I wrote a js and it look like

$('#searchform').keydown( function( event ) {
    if ( event.which == '13' ) {
        submitForm();
        return;
    }else if ( event.which == '27' ){
        alert("ESC keydown TO DO - Clear the contents from search box ");
        $('#id_search').val('');
    }
});

This will remove contents of that input box, but when i comment alert message, it will not. Could you please explain me why??

  • 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-29T03:48:08+00:00Added an answer on May 29, 2026 at 3:48 am

    OK, figured out what happens.

    In Firefox browser, the flow of events is:

    1. User press the ESC key.
    2. The keydown event handler is called, value is changed to empty string.
    3. The textbox value is “recalculated” as the keyup event occurs, resulting in the previous value.

    In other words, you can’t directly change the value during keydown event.

    One simple workaround is using a timer, changing the value after a millisecond:

    $('#searchform').keydown( function( event ) {
        if ( event.which == '13' ) {
            submitForm();
            return;
        }else if ( event.which == '27' ){
            //alert("ESC keydown TO DO - Clear the contents from search box ");
            window.setTimeout(function() {
                $('#id_search').val('');
            }, 1);
        }
    });
    

    Updated fiddle.

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

Sidebar

Related Questions

My project folders look like this Makefile /src /flash build.xml /blabla ... I wrote
I wrote some test code like this which compiled and worked fine... void threadtest()
A few years ago I wrote a WCF service, which runs on a Windows
I have two tables that look like this: Products: id category name description active
I wrote a python program which I call with arguments from console. As the
Hey all,(im a beginner in rails) i've created a controller that look like that:
I currently have an application that look like a book: several pages, and 2
I just wrote a Flex app which handles some Wikipedia text content as strings.
Ok so here's the problem: I wrote a UserControl which receives a new value
I have Table1 and I need to get it to look like Table2: Table1

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.