[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.2

Ajax instant search results

Asked by BiSHGoD in JavaScript

Tags: instant, ajax, down, results, search

I've recently been doing a bit of ajax in some of my development sites. I've used exclusively PHP in the past. Almost no Javascript, which makes Ajax a little hard to understand.

What I want is an instant search box. When you type in a letter it searches for everything with that letter, and when you type in more it narrows down the results to what it can still be. The textbox you search in would be a virtual drop down box, the results being displayed under it (max of 5 or so). Each displayed result would probably be a link to go to the results.

I have a working copy of that but it only does the first result, it's the Javascript portion I'm stuck at I think. Also I haven't figued out how to do the drop down. Mine is just hacked together from a few tutorials and my little bit of know-how.

Examples are Yahoo Instant Search (although that is suggested rather than alphabetic from the database). Also the best example I found is from newegg.com, it's nice and plain and semi simple. I can add to it later.




In my PHP script:
<script type="text/javascript" language="JavaScript">
<!--
var xmlhttp = false;
       
if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
        xmlhttp.overrideMimeType('text/xml');
} else if (window.ActiveXObject) {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
function preSearch() {
      var theQuery = document.getElementById('query').value;
      if(theQuery !== "") {
            document.getElementById('result').innerHTML = "Searching...";
            var url = 'ajax.php?q=' + theQuery;
            xmlhttp.open('GET', url, true);
            xmlhttp.onreadystatechange = function() {
                  if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                        document.getElementById('result').innerHTML = xmlhttp.responseText + ' ';
                  } else {
                        document.getElementById('result').innerHTML = 'Error: preSearch Failed!';
                  }
            };
            xmlhttp.send(null);  
      }
}
//-->
</script>
<div id="result">&nbsp;</div>



Ajax.php:
if(empty($_GET['q'])) {
      echo '&nbsp;';
} else {
      $search = trim($_GET['q']);
      $query = mysql_query("SELECT name FROM Table WHERE name LIKE '".$search."%' ORDER BY name ASC");
      if(mysql_num_rows($query) == 0) {
            echo 'Not Found.';
      } else {
      while($row = mysql_fetch_array($query) or die(mysql_error())){
            echo $row['name'];
      }
}
}

I'm printing out the entire resulting row, so it's the Javascript part only taking the first result I think. Not sure how to get an array (and put it in some nice dropdown) in javascript.

Thanks for any help.
 
Related Solutions
Keywords: Ajax instant search results
 
Loading Advertisement...
 
[+][-]09/03/06 08:35 AM, ID: 17445755Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/03/06 08:38 AM, ID: 17445764Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/03/06 12:17 PM, ID: 17446309Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/03/06 12:19 PM, ID: 17446313Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/03/06 06:44 PM, ID: 17447174Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/04/06 02:55 AM, ID: 17448588Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/05/06 11:03 AM, ID: 17457679Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: JavaScript
Tags: instant, ajax, down, results, search
Sign Up Now!
Solution Provided By: floorman67
Participating Experts: 4
Solution Grade: A
 
[+][-]11/24/06 10:56 AM, ID: 18008870Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89