[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 378
  • Last Modified:

display javascript value in asp.net label from response

trying to use asp.net label to display response value in javascript, but it does not show up in asp.net label in form,

    function calcRoute() {

        var start = document.getElementById('startvalue').value;
        var end = document.getElementById('endvalue').value;
        var request = {
            origin: start,
            destination: end,
            travelMode: google.maps.DirectionsTravelMode.DRIVING
        };
        directionsService.route(request, function (response, status) {
            if (status == google.maps.DirectionsStatus.OK) {
                alert(response.routes[0].legs[0].distance.value);
                alert(response.routes[0].legs[0].distance.text);

                var label = document.getElementById("lbldistance");
                label.text = response.routes[0].legs[0].distance.text;
               
                directionsDisplay.setDirections(response);
            }
        });

    }
0
doramail05
Asked:
doramail05
1 Solution
 
Dale BurrellCommented:
Without seeing your code, my guess is you are using the asp.net ID which isn't the same as the DOM id.

e.g.

var label = document.getElementById("lbldistance");

Should most likely be

var label = document.getElementById("<%=lbldistance.ClientID%>");

And you'll also be needing to access the DOM version of the label text, which in this case is innerHTML e.g.

label.innerHTML =  {your response code};
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now