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

  • SEARCH
  • Home
  • 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 206231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:37:38+00:00 2026-05-11T17:37:38+00:00

The below code is very simple. I have a jQuery autocomplete bound to an

  • 0

The below code is very simple. I have a jQuery autocomplete bound to an html text input referenced by #search. When the user types something into it, a drop-out list shows suggestions from the server. If the user clicks on one of the suggestions, or presses Enter with it selected, a popup (facebox) appears showing the called page within the popup. If instead the user just wants to execute a normal search and not select a suggestion, he can do so by pressing Enter or clicking #searchButton. In other words:

  1. User types something in, e.g.
    grapefruit
  2. Selectable suggestions appear.
  3. Scenario 1: User selects a
    suggestion with mouse or keyboard,
    presses enter, or clicks it – causing that
    item to pop up, i.e. autocomplete’s
    result .handler fires (and not
    .keypress)
  4. Scenario 2: User is not interested
    in the suggestions, and instead presses
    enter OR clicks on #searchButton to execute a full search on what he’s typed into #search. Autocomplete’s result handler does not fire, instead, either the Enter keypress triggers #searchButton‘s click event, or it is triggered directly (ie, actually clicked) thereby triggering a normal search.

This works beautifully in IE6, IE7, IE8, Chrome, Safari, but NOT in firefox.

In firefox, when Enter is pressed on a suggestion, both the result handler and the keypress events fire, giving the user the facebox popup, as well as executing the full search. I figured that somehow stopping .keypress from firing if .result fires would do the trick, however, I have not been able to figure out how to do so. I tried putting using jQuery’s stopPropogation() and stopImmediatePropogation() into the .result handler in the hope that it would prevent .keypress from firing, but it didn’t change a thing.

If anyone has any thoughts, or would like to help me through this, I would be most appreciative.

Thanks in advance!

    jQuery("#search").autocomplete("/index/suggest", {
        selectFirst: false,
        formatItem: function(data, i, n, value) {
            return "<font color='#3399CC'>" + value.split("::")[0] + "</font>";
        },
        formatResult: function(data,value) {
            return value.split("::")[0];
        }
    }).result(function(event, data, formatted) {
        alert('Hello, someone selected a suggestion by clicking on it or pressing enter on it, so you\'re getting this!');
        var pieces = formatted.split("::");
        var url = '/' + pieces[1] + '/detail/?id=' + pieces[2];
        jQuery.facebox({ ajax: url });
    }).keypress(keypressHandler).blur(function() {
        alert('I don\'t want this to appear if .result above is called, and it doesnt, except in firefox! Bah!');
        jQuery(this).flushCache();
    });

    function keypressHandler(e)
    {
        if(e.which == 13) {
            if(!jQuery('#searchButton').is(':disabled')) {
                jQuery(this).blur();
                jQuery('#searchButton').focus().click();
            }
        }
    }
  • 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-11T17:37:38+00:00Added an answer on May 11, 2026 at 5:37 pm

    Have you tried unbinding the keypress event on just the search box and rebinding your own keypress handler?

    jQuery("#search").autocomplete("/index/suggest", {
        selectFirst: false,
        formatItem: function(data, i, n, value) {
            return "<font color='#3399CC'>" + value.split("::")[0] + "</font>";
        },
        formatResult: function(data,value) {
            return value.split("::")[0];
        }
    }).result(function(event, data, formatted) {
        alert('Hello, someone selected a suggestion by clicking on it or pressing enter on it, so you\'re getting this!');
        var pieces = formatted.split("::");
        var url = '/' + pieces[1] + '/detail/?id=' + pieces[2];
        jQuery.facebox({ ajax: url });
    });
    
    jQuery("#search").unbind("keypress").keypress(keypressHandler).blur(function() {
        alert('I don\'t want this to appear if .result above is called, and it doesnt, except in firefox! Bah!');
        jQuery(this).flushCache();
    });
    

    It could also be that there are other key events that are being handled instead in the autocomplete handler. I would think that you would want to remove all of them from the text input while leaving them on the autocomplete “list”. If the events handled by autocomplete are different than keypress, you may want to remove them instead.

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

Sidebar

Ask A Question

Stats

  • Questions 118k
  • Answers 118k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Depends entirely on your visitors behavior. If you anticipate/get a… May 11, 2026 at 11:31 pm
  • Editorial Team
    Editorial Team added an answer Okay, now that you specified the actually meaning of 'threadsafe',… May 11, 2026 at 11:31 pm
  • Editorial Team
    Editorial Team added an answer In the DataGrid there is a Header section where the… May 11, 2026 at 11:31 pm

Related Questions

This seems so tricky to me that I think I am overlooking something simple
I am trying to create a combobox style widget (jquery-ui compatible) andcurrently I am
I'm trying to get a web app working based on the S#arp Architecture. At
I've got a particularly tricky problem using AJAX, which works fine in IE7 and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.