autocomplete search-box to echo another box with data from database
autocomplete search-box to echo another box with data from database
I have created an auto-complete search-box, where by once I write a word, words are listed down, and I choose what I want, and it displays the choice in my input text-box. What I want is that once I search for the item, the data from the database should appear in another box. Here is my code..
$(document).ready(function()
$("#search-box").keyup(function()
$.ajax(
type: "POST",
url: "readDesease.php",
data:'keyword='+$(this).val(),
beforeSend: function()
$("#search-box").css("background","#FFF url(LoaderIcon.gif) no-repeat 165px");
,
success: function(data)
$("#suggesstion-box").show();
$("#suggesstion-box").html(data);
$("#search-box").css("background","#FFF");
);
);
);
function selectDiagnosis(val)
$("#search-box").val(val);
$("#suggesstion-box").hide();
<tr>
<td>Diagnosis-1</td>
<td>
<input type="text" id="search-box" name="search-box" placeholder="Desease Name" required="required" />
<div id="suggesstion-box"></div>
<?php
$conn = new mysqli("localhost", "root", "", "coding") or die(mysqli_error());
$sa=$_POST['search-box'];
$query = $conn->query("SELECT * FROM Diagnosis_code WHERE col2 = $sa ") or die(mysqli_error());
$fetch = $query->fetch_array();
?>
<td>
<input type="text" id="search-block" name="search-block" placeholder="block Name" required="required" value=" <?php echo $fetch ?> " />
</td>
</tr>
<!--this is readeDesease.php-->
<?php
require_once("dbcontroller.php");
$db_handle = new DBController();
if(!empty($_POST["keyword"]))
$query ="SELECT * FROM diagnosis_code WHERE col2 like '%" . $_POST["keyword"] . "%' OR col1 like '%" . $_POST["keyword"] . "%' ORDER BY col2 LIMIT 0,50";
$result = $db_handle->runQuery($query);
if(!empty($result))
?>
<ul id="diagnosis-list">
<?php
foreach($result as $diagnosis)
?>
<li onClick="selectDiagnosis('<?php echo $diagnosis["col1"]; ?>');"><?php echo $diagnosis["col2"]."<strong>".$diagnosis["col1"]."</strong>"; ?></li>
<?php ?>
</ul>
<?php ?>
the auto-complete work but what i need is when i select the item, then the data could appear into two input-box where one represent col1 and another col2
– gerald
Aug 27 at 10:46
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Could you specify your problem? What is working, and what isn't? Does the auto complete functionality work? Are you getting any sql errors?
– Martin
Aug 27 at 7:25