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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:44:39+00:00 2026-05-20T02:44:39+00:00

I have a form with a text input box which displays similar entries to

  • 0

I have a form with a text input box which displays similar entries to its current value below it when a value is input into the input box. The results are displayed, but for some reason the event handler assigned to them is not functioning properly: when I hover over them the value of the input box does not get set to their value.

Google Chrome’s Developer Tools do not detect the event handler as being attached at all.
However, when I tried a static version of the .searchResult class and put some text in it, the event handler did function correctly.

The problem seems to occur only with results that are pulled from the database.

Here is the Javascript code.

$(document).ready(function() {
    function search(searchQuery) {
        $.post("requires/search.php", {searchBit: searchQuery}, function(data) {
            $("#results").html(data);
        });
    }
    $("#searchBar").focus(function() {
        if ($("#searchBar").val() === "search...") {
            $("#searchBar").val("");
        }
        $(this).addClass("searchBarFocus");
        $(this).removeClass("searchBarBlur");
    });
    $("#searchBar").blur(function() {
        $(this).addClass("searchBarBlur");
        $(this).removeClass("searchBarFocus");
    });
    $("#searchBar").keypress(function() {
        $("#results").fadeOut(100);
        $("#results").fadeIn(100);
    });
    $("#searchBar").keyup(function() {
        search($(this).val());
    });
    $(".searchResult").mouseover(function() {
        $("#searchBar").val($(this).text());
    });
});

This is where the results are being output inside of the #results div.

<div id="search">
    <form>
        <input type="text" name="searchBit" value="search..." id="searchBar" class="searchBarBlur" 
        autocomplete="off"/>
    </form>
    <div id="results">
    </div>
</div>

This is the css for the searchResult class if it is of any use at all.

.searchResult {
    cursor: pointer;
    color: #444444;
    border-top: .1em solid #EEEEEE;
    height: 100%;
    padding: .4%;
}

.searchResult:hover {
    background-color: #77CC77;
}

Does anyone have any idea what might be causing this problem? Do I have to attach the event handler at a different point in my script?

  • 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-20T02:44:40+00:00Added an answer on May 20, 2026 at 2:44 am

    Here, I re-factored (optimized) your code:

    $(function() {
    
        var sb = $('#searchBar'),
            sbFocus = 'searchBarFocus',
            sbBlur = 'searchBarBlur',
            res = $('#results');
    
        sb.focus(function() {
            this.value == 'search...' && this.value = '';      
            $(this).removeClass(sbBlur).addClass(sbFocus);
        }).blur(function() {
            $(this).removeClass(sbFocus).addClass(sbBlur);
        }).keypress(function() {
            res.fadeOut(100).fadeIn(100);
        }).keyup(function() {
            $.post('requires/search.php', {
                searchBit: this.value
            }, function(data) {
                res.html(data);
            });
        });
    
        res.delegate('.searchResult', 'mousenter' ,function() {
            sb.val( $(this).text() );
        });
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this input in a form: <input type=text value=<script src='/js/script.js' type='text/javascript'></script> name=embed/> The
I have a form with a textarea. Users enter a block of text which
I have a an HTML form which contains the YAHOO rich text editor on
I have an input box which I want to handle two types of information,
I have a form with a style input box and a <a> tag that
I have a text box and a button, which is described with the HTML/CSS
I have an asp.net text form that contains numerous decimal fields that are optional.
I have a form with checkboxes and then text to the right of the
I have several strings in the rough form: [some text] [some number] [some more
I have a few text boxes and buttons on my form. Lets say txtBox1

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.