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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:17:20+00:00 2026-06-14T17:17:20+00:00

I made a jQuery autocomplete search to search through pages in my CI application,

  • 0

I made a jQuery autocomplete search to search through pages in my CI application, the returned JSON data includes 2 elements, “slug” of the page and “name” of the page, so im using the “name” to show on autocomplete list, and when someone selects a result or press enter key it redirects him to that page using the slug:

$(function() {
    $( "#search" ).autocomplete({
        source: "index.php/pages/get_pages",
        minLength: 2,
        select: function(event, ui) {
            $(event.target).val(ui.item.value);
            window.location.href = "index.php/pages/" + ui.item.slug;
            return false;
        }
    });

    $("#search").keypress(function(e){
        if (e.which == 13) {
            window.location.href = "index.php/pages/no-results";
            return false;
        }
    });
});

now i added another option when someone types a keyword and no results were found then he press enter it should go to the “pages” with no-results parameter.

This code worked fine on all browsers except for Firefox, it goes to no-results page in all cases.

I need it to go to no-results page only if no results were found and the user entered a random page name then pressed 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-06-14T17:17:21+00:00Added an answer on June 14, 2026 at 5:17 pm

    I think it’s about forwarding issues. When you press “Enter” button, keypress’ and autocomplete select’s functions are called both. We should insert an if logic in order to execute only one of them.

    By the way I think it’s quite logical to do forwarding operations in server side.

    $(function() {
        var isSelected = false;
        $("#search" ).autocomplete({
            source: "index.php/pages/get_pages",
            minLength: 2,
            select: function(event, ui) {
                isSelected = true;
                $(event.target).val(ui.item.value);
                window.location.href = "index.php/pages/" + ui.item.slug;
                return false;
            }
        });
    
        $("#search").keypress(function(e){
            if (e.which == 13) {
                if(!isSelected)
                {
                     window.location.href = "index.php/pages/no-results";
                }
                return false;
            }
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made this code with jquery autocomplete its just like facebook search function now
I made a simple jquery script to sort content of the page on clicking
I used the jQuery autocompletion for my Struts2 application. Pratically, my action made a
I am wondering if there exist Twitter application (demo) made with JQuery/JQuery mobile? EDIT:
I've successfully made JQuery work with Master Pages, but not JQuery UI.My header in
I want to clear the textbox having Jquery Autocomplete once the user has made
I made a jQuery model. Am trying to populate data using AJAX inside that
I am using JQuery autocomplete in one of our web pages which gets source
Is there a way to tell jQuery UI Autocomplete which JSON array indexes to
I have made a jQuery/javascript that is loading a page into a div when

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.