Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get value in jquery autocomplete

Here is my code

jquery code

$("input#shopName").autocomplete({
    source: "getShop.php",
    minLength: 2
});

The JSON value return from PHP as below

if(isset($_GET["term"])){

$query=$_GET["term"];
    $result = $dataset->get_custom_record("SELECT * FROM mc_shop WHERE shop_title like  '%" . $query . "%'  ORDER BY id");
}

 while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
        $row_array['id'] = $row['id'];
        $row_array['value'] =$row['shop_title'];

        array_push($return_arr,$row_array);
    }
echo json_encode($return_arr);

autocomplete is working fine but while selecting the value from autocomplete I need put the corresponding "id" value inside one hidden variable I don't know how to do>

like image 218
Elankeeran Avatar asked Apr 23 '11 20:04

Elankeeran


1 Answers

$("input#shopName").autocomplete({
    source: "getShop.php",
    minLength: 2,
    select: function(event, ui) { 
        $("#theHidden").val(ui.item.id) 
    }
});

See http://jqueryui.com/demos/autocomplete/#event-select

like image 140
karim79 Avatar answered Sep 22 '22 07:09

karim79