Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - autocomplete -pull the options from a db not array
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

autocomplete -pull the options from a db not array

 Post Reply Post Reply
Author
urko View Drop Down
Groupie
Groupie
Avatar

Joined: 23 September 2004
Location: Slovenia
Status: Offline
Points: 160
Post Options Post Options   Thanks (0) Thanks(0)   Quote urko Quote  Post ReplyReply Direct Link To This Post Topic: autocomplete -pull the options from a db not array
    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
Back to Top
Scotty32 View Drop Down
Moderator Group
Moderator Group


Joined: 30 November 2002
Location: Manchester, UK
Status: Offline
Points: 1682
Post Options Post Options   Thanks (0) Thanks(0)   Quote Scotty32 Quote  Post ReplyReply Direct Link To This Post 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 - WebWiz Mods and Skins

For support on my mods + skins, please use my forum.
Back to Top
urko View Drop Down
Groupie
Groupie
Avatar

Joined: 23 September 2004
Location: Slovenia
Status: Offline
Points: 160
Post Options Post Options   Thanks (0) Thanks(0)   Quote urko Quote  Post ReplyReply Direct Link To This Post 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>



Edited by urko - 17 February 2008 at 7:08am
Urko
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.