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

Community
  • 1
  • 1
GPGVM
  • 5,515
  • 10
  • 56
  • 97
  • please add a fiddle. - http://jsfiddle.net/ - you might wanna try putting `type` first. – Math chiller Sep 17 '13 at 01: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). – Jim Cote Sep 17 '13 at 01:56
  • See edit above for results of comments. – GPGVM Sep 17 '13 at 02:55
  • Please provide [jsfiddle](http://jsfiddle.net) – Dom Sep 17 '13 at 03: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', ...)`. – Ricardo Tomasi Sep 17 '13 at 03:24

0 Answers0