473,549 Members | 2,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Database table data into Javascript?

36 New Member
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 1497
GazMathias
228 Recognized Expert New Member
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 New Member
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
3237
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 PHP. To eliminate (or at least deter) people wasting time submitting phony information, we can compare the state to the zip code (one DB table)...
1
7149
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 static HTML tree using http://www.treeview.net. now i need to generate this tree dynamically. Can any one has code for this?
2
1825
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 downloading this file is being appended to the end of the file. So I am accidently modifiying every file that is placed in the database. What...
1
1184
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 database which I have to parse and use to determine what controls to place on the web form. This data is placed in the database by a separate app that we...
5
2503
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: http://www.xfeedme.com/xsdbXML/xsdbjs/runqueries.html The xsdb framework provides a flexible and well defined infrastructure to allow tabular data to be published, retrieved, and combined over the...
1
1837
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 table. The table is obviously populated from a database :) so it is dynamic. The database contains a field containing some names. This field is not a...
8
3830
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 http://www.internet.com to run the app. The app requires an internet connection and is outside of the user's network. The app would have the option to either store...
6
5585
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 only works in IE but thats perfect for my project and so is the clientside aspect of it as well, i know is easily hacked but I'm not worried about...
0
3095
by: TechnoAtif | last post by:
<?php include "dbconnect.php"; include "commonFunc.php"; ?> <!----------------------------------> <table width="80%" border="1" cellpadding="2" cellspacing="0"> <tr > <td colspan="2"><p>
5
3978
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 Fields Names: countrycode, make
0
7541
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7734
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
6065
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5385
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5107
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3512
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3493
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1960
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1074
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.