Sunday, May 31, 2015

jQuery autocomplete in PHP and force to pickup

jQuery autocomplete introduction 

 My example: autocomplete data from php
Input box values force to come from autocomplete dropdown

Two files:  jquery_autocomplete.php, tags.php
<!doctype html>
<html lang="en">
  <meta charset="utf-8">
  <title>jQuery UI Autocomplete - Default functionality</title>
  <link rel="stylesheet" href="//">
  <script src="//"></script>
  <script src="//"></script>
  <link rel="stylesheet" href="/resources/demos/style.css">
  $(function() {

    $( "#tags" ).autocomplete({
      source: 'tags.php',
      minLength : 0,

      select : function(event, ui) {
             newname = ui.item.label; 
             var url = '';
             $.post(url, ui.item.label, function(data) {
      change : function() {    
            curname = $("#tags").val();
            if(curname.trim()!= newname) {
              alert("You need to pick a tag from the tag list.");

 <form onsubmit="return false" id="editContractInfo">
<div class="ui-widget">
  <label for="tags">Tags: </label>
  <input type="text" id="tags" name="tags">


$availableTags = array(
     array("label"=>".Tbd", "value"=>".Tbd"),
     array("label"=>"ActionScript", "value"=>"ActionScript"),
     array("label"=>"AppleScript", "value"=>"AppleScript"),
     array("label"=>"Asp", "value"=>"Asp")    
echo json_encode($availableTags);

Video: jQuery autocomplete in PHP and force to pickup

No comments:

Post a Comment