Auto complete search does not get selected

Hello,

I want to implement auto search completion in php. I am attaching file for this. But i can not select the value and put into text box.

Any help will be deeply appreciated.

Thanks.
text-box-search.php
gethint.php
ManiBhushan KumarAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
Please use the code snippet to post the code samples.  It gives us a unispace font and line numbers that facilitate conversation.

text-box-search.php:
<script>
function showHint(str)
{
var cat= <?php echo $doctorId ?>;

var xmlhttp;
if (str.length==0)
  { 
  document.getElementById("txtHint").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","gethint.php?q="+str+"&p="+cat,true);

xmlhttp.send();
}
</script>
 <div class = "search_container" style="width:400px;">
       
        <input type="text" name="SelMed" id="key" class="search" onChange="add_dosage(this.value, '')"  onkeyup="showHint(this.value)" />
        <div id="txtHint"></div>

Open in new window

gethint.php
<?php
include("include/dbconnect.php");


 $sql = "select *from tbl_medicines WHERE doc_id LIKE '".$_REQUEST['p']."' AND medicine_name LIKE '".$_REQUEST['q'].'%'."' ";
$res = mysql_query($sql);
     
       
while($row = mysql_fetch_array($res))
{
	?>
	<div class="show" style='cursor:pointer;padding-bottom:5px;'>
	
	 <span class="name" style=" border: solid 1px rgb(10, 6, 6); background-color: aquamarine; "> <?php echo ucwords($row['medicine_name']);?></span>

	</div>
<?php
}
?>

Open in new window

0
Ray PaseurCommented:
From a quick first look at these two code snippets, it appears that you might want to get a foundation in how PHP and JavaScript work.  To that end, this article will point you to some good learning resources and more importantly, help you avoid the many terrible examples of code that litter the internet.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html

The first example should be discarded and replaced with jQuery.  Make a Google search for "jQuery Autocomplete" and you will find many good examples (but make sure you understand the basics before you choose something randomly from an online search).  EE has an article that can help you get started with jQuery and AJAX.
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Jquery/A_10712-The-Hello-World-Exercise-with-jQuery-and-PHP.html

The second example uses the MySQL extension, and that will have to change.  PHP is doing away with MySQL support soon (it's already deprecated) so you will want to choose MySQLi or PDO.  In my experience, the conversion is easier if you choose the object-oriented version of the MySQLi extension.  This article will help you get through the necessary conversion.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html

A map of the familiar but obsolete MySQL functions and their corresponding MySQLi and PDO equivalents is available on my web site here:
http://www.iconoun.com/mysql_mysqli_pdo_function_map.php
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ManiBhushan KumarAuthor Commented:
can anyone help me ? please
0
Ray PaseurCommented:
We may be able to help you, but surely you understand that this is not a question with an answer, it's more like "I have an apple; help me bake an apple pie."  There is some learning, there are some other ingredients, and it takes some time.  That is why I pointed you to the learning resources that will help you get enough of a knowledge foundation to begin a project like this.  You cannot expect to be successful if your approach to software development is copying some pieces of found code without understanding what you've copied.  But if you deconstruct the problem, you can make great progress and we can help guide you along the way.

The first thing you want to do is make sure your "background script" works correctly.  You should be able to test gethint.php from the browser address bar - just type the URL, adding in your parameters for p and q.  Let's try to get that working.  When you have it working, or when you find that you're stuck on the task, please post the URL here so we can show you the basics you will need to secure the script and avoid external attacks that can steal your data base.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.