Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Problem passing asp variable to javascript
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

StephenD
Senior Member

Australia
1044 Posts

Posted - 09 October 2006 :  20:40:49  Show Profile  Send StephenD a Yahoo! Message
I'm trying to pick up some variables from a url querystring and pass them into my google map:

on my map page I can pick up the variables fine using asp:
xlat = trim(Request.QueryString("xlat"))
xlong = trim(Request.QueryString("xlong"))

but can't get these variables into my javascript section:

var xlat = "<%=request.QueryString("xlat")%>";
var xlong = "<%=request.QueryString("xlong")%>";

    function load() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(xlat,xlong), 13);
         var point = new GLatLng(xlat,xlong);
         map.addOverlay(new GMarker(point, icon));

      }
    }


Any ideas?

HuwR
Forum Admin

United Kingdom
20584 Posts

Posted - 09 October 2006 :  20:59:40  Show Profile  Visit HuwR's Homepage
you can't use request.querystring in javascript, you can access the Querystring, but you would then need to parse the key value pairs yourself, however you can assign them to variables using asp and then use those variables in the javascript like so.

<%
xlat = trim(Request.QueryString("xlat"))
xlong = trim(Request.QueryString("xlong"))
%>
<script language=javascript>
var jxlat = "<%= xlat %>";
var jxlong = "<%= xlong %>";

    function load() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(jxlat,jxlong), 13);
         var point = new GLatLng(jxlat,jxlong);
         map.addOverlay(new GMarker(point, icon));

      }
    }
</script>
Go to Top of Page

StephenD
Senior Member

Australia
1044 Posts

Posted - 09 October 2006 :  21:07:48  Show Profile  Send StephenD a Yahoo! Message
Thanks Huw, almost there - the first part has picked up the coords but not passed it to the map section: (view source)

var jxlat = "115.7112";
var jxlong = "-32.30172";


    function load() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(jxlat,jxlong), 13);
         var point = new GLatLng(jxlat,jxlong);
         map.addOverlay(new GMarker(point, icon));

      }
    }

Go to Top of Page

StephenD
Senior Member

Australia
1044 Posts

Posted - 09 October 2006 :  21:14:48  Show Profile  Send StephenD a Yahoo! Message
ah it was the "" . Thanks for your help Huw!
Go to Top of Page

fizzle
Starting Member

1 Posts

Posted - 27 January 2008 :  18:09:30  Show Profile
I have a similar dilemma, and hopefully someone can help me with this.

I have an Access db that contains coordinate fields (Longitude & Latitude) that I would like to query and then use them to plot markers on a Google Map.

Unfortunately, Google uses Javascript to do this task.
I am wondering if there is a way that I can integrate ASP into the task.
(sort of like above, but I need the javascript to loop through and create new markers for as many rows of data as the query returns)

The Javascript code is as follows:
(the coordinates that I want to capture dynamically are in that first line)

var point = new GLatLng(64.834829,-147.738820);
var marker = createMarker(point,'<img src="marker1.gif">', marker1)
map.addOverlay(marker);


I'd be a happy camper if I could just do this:

var point = new GLatLng(<%=rs("latitude") %>,<%=rs("longitude") %>);
var marker = createMarker(point,'<img src="marker1.gif">', marker1)
map.addOverlay(marker);

....and then have that loop like an html table until the query reaches the last record...
but of course I'm just dreaming :P

So my question is:
Is there a way that I can generate that bit of Javascript code for every row of data that the query returns ???
If it wasn't Javascript, I could capture every row in a table... but how can something like that be done with Javascript ?
(if at all)

I'm at a loss, so any help would be appreciated.
Thanks
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.3 seconds. Powered By: Snitz Forums 2000 Version 3.4.07