0

I have a javascript function that is executing fine. When I goto update the form (client side) I get a handle on the input boxes, and can read (alert) their values but I can't set them....well it doesn't seem to set them as the client form doesn't update with the new values.

Here is the line in question:

document.getElementById("Address_AddyLat").value = results[0].geometry.location.lat();

As mentioned above both the element and the result are valid (alert). I even tried hardcoding a value in there and it didn't work??

Here is the full script:

function codeAddress()
{

    var geocoder = new google.maps.Geocoder();

    var addy1

    ......


    geocoder.geocode({ 'address': fullAddress }, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK)
        {
            document.getElementById("Address_AddyLat").value = results[0].geometry.location.lat();
            document.getElementById("Address_AddyLong").value = results[0].geometry.location.lng();
        }
        else
        {
            alert("Geocode was not successful for the following reason: " + status);
        }
    });
}

Here is the html rendered:

<input name="Address.AddyLat" class="t-input" id="Address_AddyLat" style="color: rgb(255,255,255);" type="text" data-val-required="Internal Error Address Latitude Required" data-val-number="The field Address Latitude must be a number." data-val="true" value="999.9999"/>

More Info

Adding type made no difference and just for giggles I also outputted it via alert:

OBJECT HTMLInputElement

One other thing I noticed was that the server does a reload. huh? I tried adjusting the value manually and it actually throws an error. The real problem is not related so I've opened a new so question here.

Javascript local and global variables losing scope in callback function

5
  • please add a fiddle. - jsfiddle.net - you might wanna try putting type first. Commented Sep 17, 2013 at 1:54
  • 2
    Is your script running after the DOM is loaded? Try dumping your results object to the console to see if it has the structure you are expecting (or look in the developer tools window). Commented Sep 17, 2013 at 1:56
  • See edit above for results of comments. Commented Sep 17, 2013 at 2:55
  • Please provide jsfiddle Commented Sep 17, 2013 at 3:01
  • have you tried console.log(document.getElementById("Address_AddyLat").value)? If you are looking at the HTML in the web inspector, the value won't visibly change unless you use .setAttribute('value', ...). Commented Sep 17, 2013 at 3:24

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.