Type your query into the box below (it searches for fruits and vegetables).
Smart Suggest is a "fancy" search suggestion plugin for jQuery. Smart Suggest takes auto-complete boxes to the next level.
Copy the following files and directories from the code directory of the ZIP to your project directory:
css/jquery.smartsuggest.cssjs/jquery.smartsuggest.jsimages/jquery-smartsuggest/You need to link to both the jQuery library and the files you just copied:
<link rel="stylesheet" type="text/css" href="css/smartSuggest.css" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"> <script type="text/javascript" src="js/smartSuggest.js">
Now you need to tell the plugin which input field(s) you'd like to convert to Smart Suggest boxes. Assuming your input field has an ID of field:
$(document).ready(function() {
$('#field').smartSuggest({
src: 'DATA SOURCE URL HERE'
});
});
GET query to your data source. The user's search text is sent as the q variable.search_multiple.php to see how to format it in PHP. All you essentially do is create an array then call json_encode($arr).[
# Add below block for each category
{
header: {
title: "Category Title",
num: "Number of results",
limit: "Number to display"
},
data: [
# Add below block for each result
{
primary: "Title",
secondary: "Description (Optional)",
image: "URL (Optional)",
onclick: "JavaScript to execute when clicked (Optional)"
}
]
}
]
The following parameters can be included in the Smart Suggest call. Show code for an example.
src: Required. URL to the data source for the JSON content.boxId: The ID of the results box that the plugin creates. Use % to fill in the field ID (to allow for multiple Smart Suggests on a page). (Default: %-suggestions)classPrefix: The prefix on CSS classes. (Default: ss-)executeCode: Whether or not to execute the onClick code provided in JSON. (Default: true)fillBox: You can choose to fill the input box with the selected result row (like a regular auto-complete). Note that it will still execute any JavaScript code provided. See the "auto-complete fill style" example below. (Default: false)fillBoxWith: If fillBox is set to true, this is the variable that it fills the box with (you can create a new variable in the JSON). (Default: primary)minChars: The minimum number of characters that need to be entered before the plugin kicks in and starts finding results. (Default: 2)noResultsText: The text displayed in the upper-right hand corner of the box when there are no results. (Default: No results.)resultsText: The text displayed in the upper-right hand corner of the box for the number of results. Use % to show the number of results, and $ to show the limit. (Default: $ of % results.)showEmptyCategories: If there are empty categories in the JSON data and this is set to true, it will still show the category headers. (Default: false)showImages: Whether or not to show images. If this is set to false, there is no need to provide the image URL in the JSON. (Default: true)timeoutLength: The amount of time, in milliseconds, to wait for the user to stop typing to do a search query. (Default: 500)smartSuggest() function on only one element at a time. For instance, do not do this: $('#f1, #f2').smartSuggest()smartSuggest() multiple times per page as long as the boxId is different for each instance.Visit JamesSkidmore.com to get in touch.
To download this script, please visit this link.