Language: HTML
Autocomplete
1: <input id="pname" type="text" autocomplete="off" /> 2: <input id="pname_h" type="text" /> 3: <input id="vname" type="text" autocomplete="off"/> 4: <script type="text/javascript"> 5: function formatItem(row) { 6: return row[0] + " (<strong>id: " + row[1] + "</strong>)"; 7: } 8: function findValueCallback(event, data, formatted) { 9: $("#pname").val(data.Name); 10: $("#pname_h").val(data.Id); 11: } 12: $(document).ready(function() { 13: $("#pname").autocomplete( 14: '/Home/GetProducts/', { 15: dataType: 'json', 16: parse: function(data) { 17: var rows = new Array(); 18: for(var i=0; i<data.length; i++){ 19: rows[i] = { data:data[i], value:data[i].Name, result:data[i].Id }; 20: } 21: return rows; 22: }, 23: formatItem: function(row, i, n) { 24: return row.Id+ ' - ' + row.Name; 25: }, 26: width: 300 27: }); 28: $("#pname").result(findValueCallback) 29: 30: }); 31: </script>
Report Abuse
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search

