Jump to content

Recommended Posts

ive been searching a code for auto complete search and found this code on the net. but when i tried it, it failed. hope u can help me debug it.

<script type="text/javascript">
function lookup(inputString) {
	if(inputString.length == 0) {
		// Hide the suggestion box.
		$('#suggestions').hide();
	} else {
		$.post("rpc.php", {queryString: ""+inputString+""}, function(data){
			if(data.length >0) {
				$('#suggestions').show();
				$('#autoSuggestionsList').html(data);
			}
		});
	}
} // lookup

function fill(thisValue) {
	$('#inputString').val(thisValue);
	setTimeout("$('#suggestions').hide();", 200);
}
</script>
<body>


<div>
	<form>
		<div>
			Type your county:
			<br />
			<input type="text" size="30" value="" id="inputString" onkeyup="lookup(this.value);" onblur="fill();" />
		</div>

		<div class="suggestionsBox" id="suggestions" style="display: none;">
			<img src="upArrow.png" style="position: relative; top: -12px; left: 30px;" alt="upArrow" />
			<div class="suggestionList" id="autoSuggestionsList">
				 
			</div>
		</div>
	</form>
</div>

</body>

 

the other code is this --

 

<?php

$db = new mysqli('localhost', 'root' ,'', 'countries');

if(!$db) {

echo 'ERROR: Could not connect to the database.';

} else {

if(isset($_POST['queryString'])) {

$queryString = $db->real_escape_string($_POST['queryString']);

if(strlen($queryString) >0) {

$query = $db->query("SELECT value FROM countries WHERE value LIKE '$queryString%' LIMIT 10");

if($query) {

while ($result = $query ->fetch_object()) {

        echo '<li onClick="fill(\''.$result->value.'\');">'.$result->value.'</li>';

        }

} else {

echo 'ERROR: There was a problem with the query.';

}

} else {

 

}

} else {

echo 'There should be no direct access to this script!';

}

}

?>

 

when i input a letter or phrase on the search bar the other code pops on it.

Link to comment
https://forums.phpfreaks.com/topic/223421-auto-complete-site-search/
Share on other sites

well when i type something on the search bar, the *other* code will pop on the drop down button and not the searched name. thats why i said its not working. if you said that it work in your try then it must be my code or connection to my database is not working. thankx for the reply though.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.