c# - JQuery Autocomplete/ASP.NET Webhandler to include value of another textbox -


so have been @ quite while (over week) searching google , stackoverflow , that. can't seem compilation of information make work.

[aspx page]

    <span>make</span> <asp:textbox id="make_searchbox" runat="server" tooltip="enter make"></asp:textbox>     <span>model</span> <asp:textbox id="model_searchbox" runat="server" tooltip="enter model"></asp:textbox> 

[javascript]

    <%--autocomplete function--%> <script type="text/javascript">     var value = "";     $(document).ready(function () {         $("#pagecontent_make_searchbox").autocomplete("/webhandlers/autocomplete.ashx",{             extraparams: { field: "make" },             autofill: false         });          $("#pagecontent_model_searchbox").autocomplete("/webhandlers/autocomplete.ashx", {             extraparams: { field: "model" },             autofill: false         });     });   </script> 

[ashx webhandler - c#]

    public void processrequest(httpcontext context)     {         // initializing needed vars         string query = "";         string sql = "";          // check "field" query , pass switch         string field = context.request.querystring["field"];         if (field != null)         {             switch (field)             {                 case "make":                     query = context.request.querystring["q"];                     sql = "select distinct make vehicle make '%" + query + "%'";                     break;                  case "model":                     query = context.request.querystring["q"];                     sql = "select distinct model vehicle model '%" + query + "%' , make (((make textbox value)));                     break;             }         }          string connstr = system.configuration.configurationmanager.connectionstrings["connstring"].connectionstring;         // connect database, run query , return data         using (sqlconnection connection = new sqlconnection(connstr))         using (sqlcommand command = new sqlcommand(sql, connection))         {             connection.open();             using (sqldatareader reader = command.executereader())             {                 while (reader.read())                 {                     context.response.write(reader.getstring(0) + environment.newline);                 }             }         }     } 

the above works absolutely fine make text field. when type "toy" in make field passes this:

get http://localhost:26724/webhandlers/autocomplete.ashx?q=toy&field=make 

what want after user gets make , starts writing in model field should search models pertaining make. c# side of is easy suppose, sql query, how jquery take value of make text field , add query string. note needs grab value of make text box after full not @ $document.ready.

thank in advance. sure select best answer.

the autocomplete widget has select event fires when user selects item. can use filter second autocomplete source based on user selected in first one.

here's simple example: http://jsfiddle.net/b5fwc/8/ ...

$("#tags").autocomplete({         source: availabletags,          select: function(event, ui) {             $("#books").autocomplete({                 source: filter(availablebooks, ui.item.value)             });         }     }); 

are using older version of autocomplete? don't think extraparams exists in current version.

i'm not following how you're getting q=toy part, think approach want.

$("#pagecontent_make_searchbox").autocomplete({     source: "/webhandlers/autocomplete.ashx?field=make",     select: function(event, ui) {         $("#pagecontent_model_searchbox").autocomplete({             source: "/webhandlers/autocomplete.ashx?field=model&make=" + ui.item.value         });     } }); 

then on c# side you'd need value chose make "make" query string param.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -