display javascript value in label from response

Posted on 2014-07-15
Last Modified: 2014-07-15
trying to use label to display response value in javascript, but it does not show up in 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) {

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

Question by:doramail05
    1 Comment
    LVL 21

    Accepted Solution

    Without seeing your code, my guess is you are using the ID which isn't the same as the DOM id.


    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};

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Article by: DanRollins
    This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (, we'll extend the program by adding a depth-…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now