javascript - Adding an id code into input value -


i have html code displaying geolocation :

<span id="currentlat"></span>, <span id="currentlon"></span> 

combined javascript code works perfectly. problem want display above value in textfield.

i did try :

<input id="" value="<span id="currentlat"></span>, <span id="currentlon"></span>" size="30" /> 

but give me error. how add value textfield value?

nb:

i add javascript code used know what's wrong code, maybe code cannot working in text input field.

<script>       window.onload = function() {         var startpos;          if (navigator.geolocation) {           navigator.geolocation.getcurrentposition(function(position) {             startpos = position;             document.getelementbyid("startlat").innerhtml = startpos.coords.latitude;             document.getelementbyid("startlon").innerhtml = startpos.coords.longitude;           }, function(error) {             alert("error occurred. error code: " + error.code);             // error.code can be:             //   0: unknown error             //   1: permission denied             //   2: position unavailable (error response locaton provider)             //   3: timed out           });            navigator.geolocation.watchposition(function(position) {             document.getelementbyid("currentlat").innerhtml = position.coords.latitude;             document.getelementbyid("currentlon").innerhtml = position.coords.longitude;             document.getelementbyid("distance").innerhtml =               calculatedistance(startpos.coords.latitude, startpos.coords.longitude,                                 position.coords.latitude, position.coords.longitude);           });         }       };        // reused code - copyright moveable type scripts - retrieved may 4, 2010.       // http://www.movable-type.co.uk/scripts/latlong.html       // under creative commons license http://creativecommons.org/licenses/by/3.0/       function calculatedistance(lat1, lon1, lat2, lon2) {         var r = 6371; // km         var dlat = (lat2-lat1).torad();         var dlon = (lon2-lon1).torad();         var = math.sin(dlat/2) * math.sin(dlat/2) +                 math.cos(lat1.torad()) * math.cos(lat2.torad()) *                 math.sin(dlon/2) * math.sin(dlon/2);         var c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a));         var d = r * c;         return d;       }       number.prototype.torad = function() {         return * math.pi / 180;       }     </script> 

updated see running code

<input value='<span id=\"currentlat\"></span>, <span id=\"currentlon\"></span>' size="30" />     <input value="<span id='currentlat'></span>, <span id='currentlon'></span>" size="30" />

and if want set width , height should be

  style="height:100px;width:200px" 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -