Jquery Mutliple value autocomplete with php mysql
I am trying to implement jquery multiple value auto-complete with php and
mysql, I am getting auto-complete on first search term, but after
selecting it, its doesn't show auto-complete for 2nd search term after
comma.
Please for the same, thanks in advance. Below are the file codes.
searchp.php file Code :
<link
href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css""
rel="stylesheet"/>
<form action='' method='post'>
<p><label>Skills:</label><input type='text' name='search' value=''
id="search"></p>
</form>
<script type="text/javascript"
src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript"
src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
$(function() {
function split( val ) {
return val.split( /,\s*/ );
}
function extractLast( term ) {
return split( term ).pop();
}
$( "#search" )
.bind( "keydown", function( event ) {
if ( event.keyCode === $.ui.keyCode.TAB &&
$( this ).data( "ui-autocomplete" ).menu.active ) {
event.preventDefault();
}
})
.autocomplete({
minLength: 0,
source:'auto-skills.php',
focus: function() {
// prevent value inserted on focus
return false;
},
select: function( event, ui ) {
var terms = split( this.value );
// remove the current input
terms.pop();
// add the selected item
terms.push( ui.item.value );
// add placeholder to get the comma-and-space at the end
terms.push( "" );
this.value = terms.join( ", " );
return false;
}
})
});
</script>
auto-skills.php File Code
<?php
include_once("include/#config.php");
$q = strtolower($_GET["term"]);
$req = "SELECT SkillName FROM skills WHERE SkillName LIKE '%".$q."%' AND
SkillStatus = 1 ";
$query = mysql_query($req);
while($row = mysql_fetch_array($query))
$results[] = array('label' => $row['SkillName']);
echo json_encode($results);
?>
No comments:
Post a Comment