Monthly Archives: July 2013

How to make a JSON object with PHP array for jQuery autocomplete?

This php code creates JSON object like ” availableTags “

	var availableTags = [
	{key: "1",value: "NAME 1"},{key: "2",value: "NAME 2"},{key: "3",value: "NAME 3"},{key: "4",value: "NAME 4"},{key: "5",value: "NAME 5"}
	 ];

$Acc_Name_List is your PHP array which have key and value. You can manipulate as you want, make function or add into your class.

            var availableTags = [
                $value_name)
                {
                  if ($key != 0 && $key != "" && $value_name != "")
                  {
                   $list_key = "key: ". '"'.$key.'"';
                   $list_value = "value: ". '"'.$value_name.'"';
                   // $string .= $list_value.',';
                     $string .="{". $list_key.','.$list_value."},";
                  }
                }
                $string = substr($string, 0, -1);
               // echo $result;
                echo $string;
                ?>
Share

JQuery – how to get a key and value with autocomplete?

Jquery autocomplet is easy but when you have to get the key of the array and store into the database or just you want to get it’s a bit tricky.
I have used the jquery UI autocomplete feature with JSON object which you can create with given PHP code.
As soon as you choose a list of the values, key automatically gets populated into another hidden field. For sake of understanding I made it text field.
You can do whatever you want with that id!!







Share

How to pass dropdown value to text box ?

I had a situation where requirement was to pass select box value to another text field. Using jQuery it is very easy.

See the code below.








Share