autocomplete -pull the options from a db not array
Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=25306
Printed Date: 29 March 2026 at 7:01pm Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com
Topic: autocomplete -pull the options from a db not array
Posted By: urko
Subject: autocomplete -pull the options from a db not array
Date Posted: 16 February 2008 at 2:31pm
hi
I have found a .js for autocomplete. Script works perfectly, but Im just
wondering if it's possible to get records from database ( i use MS
access) and not array.
this is the part of js where options are written:
<script> var customarray=new Array('an apple','alligator','elephant','pear','kingbird','kingbolt', 'kingcraft','kingcup','kingdom','kingfisher','kingpin'); var custom2 = new Array('something','randomly','different'); </script>
|
and this is a rs, but i dont get it to work.
<% Function GetPDFsArray()
Dim objRs
Set objRs = Server.CreateObject("ADODB.Recordset")
mySQL = "SELECT description, sku, price " _ & "FROM Products "
objRs.Open mySQL, connString
If NOT objRs.EOF OR NOT objRs.BOF Then GetPDFsArray = objRs.GetRows() Else GetPDFsArray = "" & objRs("description") & "" End If
End Function
Dim arrPDFs arrPDFs = GetPDFsArray
If isArray(arrPDFs) Then for i=0 to uBound(arrPDFs,2)
Dim javascriptArrayValues javascriptArrayValues=javascriptArrayValues & """" & arrPDFs(0,i) & """" & "," next 'i javascriptArrayValues=Left(javascriptArrayValues,Len(javascriptArrayValues)-1) Else javascriptArrayValues = "Error: No results for array" End If %>
|
Any kind of help would be great.
Thanks
------------- Urko
|
Replies:
Posted By: Scotty32
Date Posted: 16 February 2008 at 10:14pm
Based on a very quick look i would assume it would be the fact you add a comma to every value, including the last value which i assume would break the Javascript.
You could try this quick mod:
for i=0 to uBound(arrPDFs,2)
Dim javascriptArrayValues javascriptArrayValues=javascriptArrayValues & """" & arrPDFs(0,i) & """" if i <> uBound(arrPDFs,2) then javascriptArrayValues=javascriptArrayValues & ", "
next 'i
|
This will only add a comma to values that are not the last value.
------------- S2H.co.uk - http://www.s2h.co.uk/wwf/" rel="nofollow - WebWiz Mods and Skins
For support on my mods + skins, please use http://www.s2h.co.uk/forum/" rel="nofollow - my forum .
|
Posted By: urko
Date Posted: 17 February 2008 at 7:05am
thanks for the reply.
as im new to javascript, do i also need to change something where the options are writen in order to get the results from db? this is the code that is added below the <input type="text"....> on search.asp
var obj = actb(document.getElementById('tb'),customarray); //setTimeout(function(){obj.actb_keywords = custom2;},10000); </script>
|
------------- Urko
|
|