473,387 Members | 1,303 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Database table data into Javascript?

36
Hi Guys

I am using the following script to pull in 10 UK postcodes into my page:

Expand|Select|Wrap|Line Numbers
  1. <%
  2. sqlStrB = "Select TOP 10 * from postcodetable"
  3.  
  4.   oRsBJ.Open sqlStrB, oDBConn 
  5.   If oRsBJ.eof then
  6. %>
  7. Sorry there are no postcodes
  8. <%
  9.   Else
  10.   %>
  11.  
  12. ---
  13.  
  14. <%
  15.         Do while not oRsBJ.eof
  16.  
  17.         postcode = oRsBJ("postcode") 
  18. %>
  19.  
  20. <%=postcode%>
  21.  
  22. <%
  23.         oRsBJ.MoveNext
  24.         loop 
  25. %>
  26.  
  27. ---
  28.  
  29. <%
  30.   End If
  31.   %>
  32.  
  33. <%
  34. oRsBJ.close
  35. set oRsBJ = nothing
  36. %>
  37.  
  38.  
This works just fine. However, I want to pull in these postcodes into the following peice of javascript:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. var locations = [
  3.     'POSTCODE, UK',
  4.     ];
  5. </script>
  6.  
So, if my query returns 3 postcodes then the javascript script would look like:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. var locations = [
  3.     'LU4 9LT, UK',
  4.     'HP2 5UY, UK',
  5.     'WD2 6TF, UK',
  6.     ];
  7. </script>
  8.  
How do I insert all the postcode from my query into the javascript in the format above?

Any help would be fully appreciated

Best regards

Rod from the UK
Feb 23 '10 #1
2 1488
GazMathias
228 Expert 128KB
Did you solve this?

If not simply response.write out your recordset in the loop at that place in the javascript.

Expand|Select|Wrap|Line Numbers
  1. <%
  2. sqlStrB = "Select TOP 10 * from postcodetable"
  3. oRsBJ.Open sqlStrB, oDBConn
  4. %>
  5.  
  6. <script type="text/javascript">
  7. var locations = [
  8.  <% do while not oRsBJ.eof
  9.        response.write "'" & oRsBJ("postcode") & "'," & vbnewline
  10.       oRsBJ.movenext
  11.       Loop %>
  12.     ];
  13. </script>
  14. <%oRsBJ.close
  15. set oRsBJ = nothing%>
  16.  
Mar 1 '10 #2
rjoseph
36
Thanks Gaz.

I will use this in my code.

Thanks for all your help

Best regards

Rod from the UK
Mar 1 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Eric Linders | last post by:
Hi everyone. :-) Our site gets a ton of traffic on our contact forms, which collect the standard information (name, address, city, state, zip, home phone, etc.) The form validation is done with...
1
by: Srihari | last post by:
I'm trying to develop a tree structure using javascript. The node values of the tree are generating from a mysql table depending on login. The tree structure contains 3 sub levels. I developed...
2
by: Ryan Taylor | last post by:
Hello. I am trying to upload a file and save it in a Sql Server 2000 database. This seems to be working fine. However, when I download the file from SQL Server, it appears that the page that is...
1
by: Kent Ogletree | last post by:
I am converting an app from JavaScript ASP pages to ASP.NET in VB and have not found a good reference for the XML classes in .NET as of yet. What I have is XML encoded data in a field in my...
5
by: aaronwmail-usenet | last post by:
Hi folks. I'd really like some comments or flames please :). I've ported my xsdb database engine to javascript. I put up a demo page here: ...
1
by: Fix_Metal | last post by:
Hello all. I'm new to this group :) I have a problem with javascript language. I'm making an .asp page with some integrated Javascript functions. The page consists of some HTML selects and a...
8
by: mouac01 | last post by:
I'm not sure if this is possible. I would like to have a PHP app on the Internet connect and write to a local database (Intranet). For example, users would go to a web site...
6
by: shuttered | last post by:
Can anyone help me on this? I just need more information on all aspects of it. For example : how to add, delete, edit fields. Can i add new tables etc.. i know it is MS version of javascript so it...
0
by: TechnoAtif | last post by:
<?php include "dbconnect.php"; include "commonFunc.php"; ?> <!----------------------------------> <table width="80%" border="1" cellpadding="2" cellspacing="0"> <tr > <td...
5
by: giandeo | last post by:
Hello Experts. Could you find a solution for this problem please! I have the following tables in Access Database Table Name: origin Fields Names: country, countrycode Table Name: make...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.