Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Table data into javascript?

Author  Topic 

rjoseph
Starting Member

3 Posts

Posted - 2010-02-23 : 17:03:12
Hi Guys

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


<%
sqlStrB = "Select TOP 10 * from postcodetable"

oRsBJ.Open sqlStrB, oDBConn
If oRsBJ.eof then
%>
Sorry there are no postcodes
<%
Else
%>

---

<%
Do while not oRsBJ.eof

postcode = oRsBJ("postcode")
%>

<%=postcode%>

<%
oRsBJ.MoveNext
loop
%>

---

<%
End If
%>

<%
oRsBJ.close
set oRsBJ = nothing
%>



This works just fine. However, I want to pull in these postcodes into the following peice of javascript:


<script type="text/javascript">
var locations = [
'POSTCODE, UK',
];
</script>


So, if my query returns 3 postcodes then the javascript script would look like:


<script type="text/javascript">
var locations = [
'LU4 9LT, UK',
'HP2 5UY, UK',
'WD2 6TF, UK',
];
</script>


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

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-24 : 09:35:43
you might be better off posting this in ASP.NET or javascript forums.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -