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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:33:29+00:00 2026-06-09T23:33:29+00:00

I have a searchable textbox which populates a div with the search results. The

  • 0

I have a searchable textbox which populates a div with the search results. The div is scrollable. What I am trying to achieve, is to navigate through the result items with page up and down (keycode 38 & 40). But as soon as I try this, the whole div scrolls, and the result item itself does not take on the new selected css class.

Below is some of my code

this.TagNavigation = function (event) {
    var div = $("#TagSearchResults");
    var anchors = $("#TagSearchResults a");
    var selectedAnchor = $("#TagSearchResults a.selected");
    var position = anchors.index(selectedAnchor);

        if (event.keyCode == "13" && anchors.length > 0) {
            FRAMEWORK.AddUpdateInterventionTags(selectedAnchor.attr("id").split("-")[1] + "|" + selectedAnchor.text(), "add");
        }
        if (event.keyCode == "13" && anchors.length == 0 && $("#txtTagSearch").val() != "Start typing to search Tags") {
            FRAMEWORK.AddNewTag($("#txtTagSearch").val());
        }
        else if (event.keyCode == "38") {

            if (position > 0) {
                canClose = false;
                selectedAnchor.removeClass("selected");
                var newSelectedAnchor = $(anchors.get(position - 1));
                newSelectedAnchor.addClass("selected");
                $("#txtTagSearch").val(newSelectedAnchor.text());
            }
        }
        else if (event.keyCode == "40") {

            if (position <= anchors.length) {
                canClose = false;
                selectedAnchor.removeClass("selected");
                var newSelectedAnchor = $(anchors.get(position + 1));
                newSelectedAnchor.addClass("selected");
                $("#txtTagSearch").val(newSelectedAnchor.text());
                //newSelectedAnchor.focus();
            }
        }
    };

    this.AjaxSearch = function (text) {
        var div = $("#TagSearchResults");
        var anchors = $("#TagSearchResults a");
        var selectedAnchor = $("#TagSearchResults a.selected");
        var position = anchors.index(selectedAnchor);

        if (event.keyCode == "13") {
            FRAMEWORK.TagNavigation(event);
        }
        else if (event.keyCode == "38") {
            FRAMEWORK.TagNavigation(event);
        }
        else if (event.keyCode == "40") {
            FRAMEWORK.TagNavigation(event);
        }
        else if (text.length >= 3) {
            FRAMEWORK.RenderSearchResults(text);
        }
        else {
            $("#TagSearchResults").html("");
            $("#TagSearchResults").hide();
        }
    };

As you can see in the TagNavigation function (keycode 40), I tried to set the focus on the active element, but still no success.

Any help please.

  • 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-09T23:33:30+00:00Added an answer on June 9, 2026 at 11:33 pm

    You need to check weather the newly selected element has a higher Y value that the bottom of the containing div. If so, then scroll the div by the height of the new element. Change your ‘if (event.keyCode == “40”)’ statement to the following:

    this.TagNavigation = function (event) {
            var div = $("#TagSearchResults");
            var anchors = $("#TagSearchResults a");
            var selectedAnchor = $("#TagSearchResults a.selected");
            var position = anchors.index(selectedAnchor);
    
            if (event.keyCode == "13" && anchors.length > 0) {
                FRAMEWORK.AddUpdateInterventionTags(selectedAnchor.attr("id").split("-")[1] + "|" + selectedAnchor.text(), "add");
            }
            if (event.keyCode == "13" && anchors.length == 0 && $("#txtTagSearch").val() != "Start typing to search Tags") {
                FRAMEWORK.AddNewTag($("#txtTagSearch").val());
            }
            else if (event.keyCode == "38") {
    
                if (position > 0) {
                    canClose = false;
                    selectedAnchor.removeClass("selected");
                    var newSelectedAnchor = $(anchors.get(position - 1));
                    newSelectedAnchor.addClass("selected");
                    $("#txtTagSearch").val(newSelectedAnchor.text());
                    var newSelectedAnchorPosistion = newSelectedAnchor.offset();
                    var divPosition = div.offset();
                    divPosition = divPosition.top;
                    if (newSelectedAnchorPosistion.top + 1 > divPosition) {
                        var newPos = div.scrollTop() - newSelectedAnchor.outerHeight();
                        div.scrollTop(newPos);
                    }
                }
            }
            else if (event.keyCode == "40") {
                if (position < anchors.length - 1) {
                    canClose = false;
                    selectedAnchor.removeClass("selected");
                    var newSelectedAnchor = $(anchors.get(position + 1));
                    newSelectedAnchor.addClass("selected");
                    $("#txtTagSearch").val(newSelectedAnchor.text());
                    var newSelectedAnchorPosistion = newSelectedAnchor.offset();
                    var divPosition = div.offset();
                    divPosition = divPosition.top + div.outerHeight();
                    if (newSelectedAnchorPosistion.top + 1 >= divPosition) {
                        var newPos = div.scrollTop() + newSelectedAnchor.outerHeight();
                        div.scrollTop(newPos);
                    }
                }
            }
        };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database full of items, which should be searchable by any or
I currently have 6 100mb+ PDF documents which have searchable text layer enabled. However
I have a PDF which is searchable and I need to convert it into
I have a search function in my project. In the searchable.xml, i would like
I'm trying to make a searchable phone/local business directory using Apache Lucene. I have
I have a site with content that is searchable using a search bar that
For my Grails App i use Searchable Plugin to have an nice google-like Search.
Im having some conflicts with the Searchable plugin. I have a filter which fetches
I have a site which is searchable using Lucene. I've noticed from logs that
In my searchable.xml, I have: android:voiceSearchMode=showVoiceSearchButton|launchRecognizer I get the search string returned SearchManager like

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.