Label value to javascript variable

Hey,

i’d like to have 2 javascript variables that will get its values from 2 labels. The problem is that the values are numbers and i get an error using my code. Any ideas on how this should be done?

function load() {
            if (GBrowserIsCompatible()) {
                var map = new GMap2(document.getElementById("map"));
                var lat = parseFloat(document.getElementById("lat_lbl").value);
                var lng = parseFloat(document.getElementById("lng_lbl").value);
                map.setCenter(new GLatLng(lat, lng), 10);
                map.addOverlay(new GMarker(new GLatLng(lat, lng)));
                                         }
                             }
<asp:Label ID="lat_lbl" runat="server" Text="-33.9417"></asp:Label>&nbsp;
<asp:Label ID="lng_lbl" runat="server" Text="150.9483"></asp:Label>

What happens if you alert(document.getElementById(“lat_lbl”)) ?
…and what happens if you alert(document.getElementById(“lat_lbl”).value); ?

alert(document.getElementById(“lat_lbl”));
returns “[object HTMLSpanElement]”

alert(document.getElementById(“lat_lbl”).value);
returns “undefined”

What kind of element does the following return in HTML?
<asp:Label ID=“lng_lbl” runat=“server” Text=“150.9483”></asp:Label>

If you inspect your html code - or do a view source even - what element is the Label as?

You could try one of the following:
alert(document.getElementById(“lat_lbl”).innerHTML);
alert(document.getElementById(“lat_lbl”).Text);

What kind of element does the following return in HTML?

not quite sure what you mean but this is what i get in source view “<span id=“lng_lbl”>150.9473</span>”

alert(document.getElementById(“lat_lbl”).innerHTML);

returns “-33.9417”

alert(document.getElementById(“lat_lbl”).Text);

returns “undefined”

So your code would be:

function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById(“map”));
var lat = parseFloat(document.getElementById(“lat_lbl”).innerHTML);
var lng = parseFloat(document.getElementById(“lng_lbl”).innerHTML);
map.setCenter(new GLatLng(lat, lng), 10);
map.addOverlay(new GMarker(new GLatLng(lat, lng)));
}
}

sweet!! Thanks a million, it works!!