Jump to content

Creating a Submit Button in PHP/jQuery/AJAX Autosuggest search


slaterino

Recommended Posts

Hi,

I am having my first foray into the world of AJAX and Javascript and have created an Autosuggest search page. However, I want to have a submit button that will list all database entreies that match the search query and I can't work out what the best way to do this! Would it be using a input button and some kind of onClick fucntion? If so, does anyone know what the onClick function would be in jQuery? Would I need to create some new script for this? If anyone can give me any guidance on this I will be eternally grateful. Here is the code:

 

<?php
$db = new mysqli('128.0.0.1', 'asad' ,'asad', 'asad');
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 DISTINCT OrgType FROM Contacts WHERE OrgType LIKE '$queryString%' LIMIT 10");
			if($query) {

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

         			echo '<li onClick="fill(\''.$result->OrgType.'\');">'.$result->OrgType.'</li>';
         		}
			} else {
				echo 'ERROR: There was a problem with the query.';
			}
		} else {
		} 
	} else {
		echo 'There should be no direct access to this script!';
	}
}
?>

Link to comment
Share on other sites

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.