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
  • 2 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 a input box which looks like below, <input id=basic-search type=text value=Enter keyword
I have the following text input on a budget calculator form which displays the
I have a form in which I have 30 input boxes and 10 text
I have a form ,in that there have a text box which can take
I have a Date Input text box generated by jquery Date Picker which is
I have a form which is essentially an autocomplete input box. I can get
I have a form which the client wants the labels inside the input box
I have a form with two input text fields: <input id=ModelName_test_0 name=ModelName[test][0] type=text> <input
I have form like this: <div class=satu> <input type='text' size='1' maxlength='1' name='score[1][]' id='score[1][]'> </div>
I have form with multiple input type=radio with text next to them. I want

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.