jquery - autocomplete specify more parameters? -
i'm using jquery ui autocomplete
if in jquery / asp.net:
$("#<%= txtname.clientid %>").livequery(function () { $(this).autocomplete('loadnames.ashx') .result(function (event, data, formatted) { // data[0] : name, data[1] :addressid // set selected email id hidden field $("#<%= hdnid.clientid %>").val(data[1]); if (data[1] != "0") { var url = "http://emps/newentry.aspx?id=" + data[1]; window.open(url); } else { } }); });
this works great, want add more parameters minchars, etc. try this:
$("#<%= txtname.clientid %>").livequery(function () { $(this).autocomplete({source:"loadnames.ashx", delay:100, minchars:2}) .result(function (event, data, formatted) { // data[0] : name, data[1] :addressid // set selected email id hidden field $("#<%= hdnid.clientid %>").val(data[1]); if (data[1] != "0") { var url = "http://emps/newentry.aspx?id=" + data[1]; window.open(url); } else { } }); });
this doesnt work longer. how can add more parameters minchars, delay, etc this?
from comments wanted see .ashx file, there no issue this. want add additional parameters autocomplete:
public class loadnames : ihttphandler { public void processrequest(httpcontext context) { dataset ds = null; dictionary<long, string> lstaddresses = new dictionary<long, string>(); ds = getloginnames(); if (ds.tables[0].rows.count > 0) { foreach (datarow dr in ds.tables[0].rows) { lstaddresses.add(convert.toint64(dr["loginid"].tostring()), dr["login"].tostring()); } stringbuilder builder = new stringbuilder(); foreach (keyvaluepair<long, string> item in lstaddresses) { builder.append(string.format("{0}|{1}|{2}", item.value, item.key, environment.newline)); } context.response.write(builder.tostring()); } } public dataset getloginnames() { sqlcommand cmdselect = default(sqlcommand); sqlconnection conmydata = default(sqlconnection); sqldataadapter daissues = default(sqldataadapter); system.data.dataset ds = null; conmydata = null; //try , make connection try { conmydata = new sqlconnection(system.configuration.configurationmanager.appsettings["connstring"]); cmdselect = new sqlcommand("selfullnames", conmydata); var _with1 = cmdselect; _with1.commandtype = system.data.commandtype.storedprocedure; //add parameters _with1.parameters.add("@inactive", sqldbtype.int).value = 2; daissues = new sqldataadapter(); daissues.selectcommand = cmdselect; ds = new system.data.dataset(); daissues.fill(ds); return ds; //catch exceptions might thrown } catch (exception e) { throw e; //clean , close resources } { conmydata.close(); cmdselect = null; conmydata = null; } } public bool isreusable { { return false; } }
$(document).on("keydown.autocomplete", "#<%= txtname.clientid %>", function (e) { $(this).autocomplete({ source: "loadnames.ashx", delay: 100, minlength: 2 }).result(function (event, data, formatted) { $("#<%= hdnid.clientid %>").val(data[1]); if (data[1] != "0") { var url = "http://emps/newentry.aspx?id=" + data[1]; window.open(url); } else {} }); });
Comments
Post a Comment