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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:38:56+00:00 2026-06-15T12:38:56+00:00

I am trying to generate suggestions using data in a database without refreshing the

  • 0

I am trying to generate suggestions using data in a database without refreshing the page as a user types some data in the input field below. AJAX is quite new to me and I have been trying to figure out where I went wrong for quite some time now. It seems as if the code below is not returning any results at all. I appreciate any help.

My markup:

<head>
<title>Test</title>

<script type="text/javascript">
    function search(searchword) {
      $('#suggestion').load('invoice-get-data.php?searchword=' + searchword);
    }
</script>
</head>
<body>

<div class="prod-name">
    <!-- As user input data, call search function, and narrow down results on every keystore -->
    <input onKeyPress="search(this.value)" type="text" id="prod-name"/>
    <div id="suggestion"></div>
</div>

</body>

AJAX so far:

<?php   
    $conn = mysql_connect('localhost', 'root', 'mypassword');

    if(!$conn){
        die('Error: Unable to connect.' . '<br>' . mysql_error());
    }

    mysql_select_db("mydb", $conn);

    $searchword = $_GET['searchword'];

    $results = mysql_query("SELECT * FROM products WHERE prod-name LIKE '$searchword'") or die(mysql_error());


    while($row = mysql_fetch_array($results)){
        echo $row['prod-name'] . '<br/>';
    }


?>
  • 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-15T12:38:59+00:00Added an answer on June 15, 2026 at 12:38 pm

    for starters, the “onchange” event doesn’t fire until a textbox has lost focus (meaning the cursor goes out of the textbox). You are probably looking for a keyboard event like onkeyup or onkeypress.

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

Sidebar

Related Questions

Im trying to generate a color gradient using ColdFusion. My current code below works
I'm trying to generate a LINQ OrderBy clause using lambda expressions with an input
I'm trying to generate the following html code using cl-who: <html> <body> <div id=cnt_1></div>
Im am trying to generate interfaces of HP Quality Center OTACLien.dll using com4j. I
I'm trying to create a procedure which extracts data from a MySQL server (using
I'm trying to set up a simple login using AuthLogic into my User table.
Im writing some code in R whereby i need to generate a data set
I'm trying to do some work between java and r (using some of the
I just started trying to visualize my data by using the ggplot2 package in
Trying to generate JavaDocs for the Android lint-cli project on Mac 10.7 Keep getting

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.