javascript - Outputting Distance Matrix results in a div -


i'm using code found here calculate distance between places.

here's fiddle , code:

<!doctype html> <html> <head> <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> <script type="text/javascript"> origin = new google.maps.latlng(40.689844,-74.044874), destination = "washington, dc", service = new google.maps.distancematrixservice();  service.getdistancematrix( {     origins: [origin],     destinations: [destination],     travelmode: google.maps.travelmode.driving,     avoidhighways: false,     avoidtolls: false },  callback );  function callback(response, status) {     orig = document.getelementbyid("orig"),     dest = document.getelementbyid("dest"),     dist = document.getelementbyid("dist");  if(status=="ok") {     orig.value = response.destinationaddresses[0];     dest.value = response.originaddresses[0];     dist.value = response.rows[0].elements[0].distance.text; } else {     alert("error: " + status); } } </script> </head> <body> <br> basic example using distance matrix.<br><br> origin: <input id="orig" type="text" style="width:35em"><br> destination: <input id="dest" type="text" style="width:35em"><br> distance statue of liberty washington dc, usa (by car): <input id="dist" type="text" style="width:35em"><br> </body> </html> 

everything works fine, i'd change input tags div tags. however, if change "input id" "div id", doesn't work:

origin: <div id="orig" type="text" style="width:35em"></div> destination: <div id="dest" type="text" style="width:35em"></div> distance statue of liberty washington dc, usa (by car): <div id="dist" type="text" style="width:35em"></div> 

shouldn't irrelevant if it's div, input, span or whatever, long has id? should changed output results in div? thank you.

a <div> doesn't have value property, input fields. can set innerhtml or textcontent properties.

orig.innerhtml = response.destinationaddresses[0]; 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -