tags:

views:

106

answers:

3

I am using Jquery Autocomplete

I am also using the formatItem. I would like the output to be

<json.key: json.value

ex

Name: Adam

However i cant get the json data using the 4th param and i am getting the full json string as the 4th param and one result. How do i use json with this? is another autocomplete recommended? (this one looks pretty good...)

+1  A: 

Check out the jQuery UI Autocomplete plugin

PetersenDidIt
+2  A: 

This article should help point you in the right direction: http://blog.schuager.com/2008/09/jquery-autocomplete-json-apsnet-mvc.html

ntownsend
Excellent link, excellent answer.
acidzombie24
+1  A: 

i'm using the jQuery UI with this code:

function initAutocomplete() {
        $("#tbDevices").autocomplete("Static/ui.autocomplete/GetDevices.ashx", {
            width: 160,
            selectFirst: false,
            max: 100,
            autoFill: true,
            matchContains: true,
            highlightItem: true,
            parse: function(data) {
                return $.map(eval(data), function(row) {
                    return {
                        data: row,
                        lable: row.lable, //value being searched for
                        value: row.value //value in text input
                    }
                });
            },
            formatItem: function(row, i, max, term) {
                return "<span style='font-size: 110%;'>" + row.lable + "</span><br/>" + "ID: " + row.value;
            },
            formatResult: function(row, i, max) {
                return row;
            }
        }).result(function(event, item) {
            document.getElementById('#hdnChosenDevice').value = item.value;
            $('#tbDevices').val(item.lable);
        });
    }   

the ashx file is returning a string with json :

[{"lable":"device1","value":"01"},{"lable":"device2","value":"02"}]
danfromisrael