sql server - jQuery autocomplet from database with asp -


i have asp page, , need show table of data sql server database, want select city names 2 text areas example(source , destination) , show informations of row. here copy of autocomplete.html:

    <!doctype html> <html lang="en">     <head>         <meta charset="utf-8" />         <title></title> <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" /> <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script> <link rel="stylesheet" href="/resources/demos/style.css" /> <script> $(function() { var availabletags = [ "shanghai", "shenzhen", "casablanca", "jeddah", "paris", "php", "london", "tokyo", "jeddah", "istambul" ]; $( "#tags" ).autocomplete({ source: availabletags }); }); </script>     </head>     <body>     </body> </html> 

in page index.asp:

    ....     <!--#include file="autocomplete.html"--> <label for="tags"> pod </label> <input id="tags" />     <br> 

i want jquery autocomplete source , destination database not way:

var availabletags = [ "shanghai", "shenzhen", "casablanca", "jeddah", "paris", "php", "london", "tokyo", "jeddah", "istambul" ]; 

how ??

thank help!

you can use classic asp form. try putting code brackets inside array list so...

var availabletags = [<%=getcities() %>]; 

your getcities() function output response object list of required cities.

-- edit --

the following code has not been tested. may need modify parts appropriate needs:

const c_no_data = "no_data"              'used when no data returned consuming routine const c_error   = "error"                'used when error generated - fed comsuming routine  'getdataset '    returns table of data based on supplied sql statement , connection string. 'parameters: '    sqlstring (string) - sql string sent. '    connstring (string) - database connection string. 'usage: '    dataset = getdataset(sqlstring, connstring) 'description: '    function generates table of information in 2 dimensional array.  first dimension represents columns '    , second rows.  if error occurs while routine executing array , base index (0,0) set  '    c_error, (0,1) vbscript error index, , (0,2) vbscript error description. function getdataset(sqlstring, connstring)     'initialise...     dim returnval, rsdata     on error resume next         'define , open recordset object...         set rsdata = server.createobject("adodb.recordset")         rsdata.open sqlstring, connstring, 0, 1, 1         'initialise empty value containing array...         redim returnval(0,0)         returnval(0,0) = c_no_data         'deal errors...         if not rsdata.eof , not rsdata.bof             'store data...             returnval = rsdata.getrows()             'tidy up...             rsdata.close             set rsdata = nothing             select case err.number                 case 3021    'no data returned                     'do nothing initial value still exist (c_no_data)                 case 0        'no error                     'do nothing data has been returned                 case else                     redim returnval(4,0)                     returnval(0,0) = c_error                     returnval(1,0) = err.number                     returnval(2,0) = err.description                     returnval(3,0) = sqlstring                     returnval(4,0) = connstring             end select         end if     on error goto 0     'return array...     getdataset = returnval end function  function getcities()     dim sql, tcity, rc, max, rv     sql = _         "select " & _             "'""' + city_name + '""' city " & _         "from  " & _             "clkj_freight  " & _         "where  " & _             "pol = '" & replace(request.querystring("q"), "'", "''") & "'"     tcity = getdataset(sql, conn)     if tcity(0, 0) = c_error or tcity(0, 0) = c_no_data rv = tcity(0, 0)     max = ubound(tcity, 2) '2 second dimension of array     rc = 0 max         response.write(tcity(rc, 0))         if rc<max response.write(",")     next 'rc     'if error encountered or no data returned notify user (this behaviour may changed if necessary)...     getcities = rv end function 

Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -