Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to input javascript variables in to html code?
    primarykey
    data
    text
    <p>I am trying to create a mileage calculator for an app, and I found the code online.</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;meta name="viewport" content="initial-scale=1.0, user-scalable=no"/&gt; &lt;script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; var directionDisplay; var map; function initialize() { directionsDisplay = new google.maps.DirectionsRenderer(); var copenhagen = new google.maps.LatLng(55.6771, 12.5704); var myOptions = { zoom:12, `enter code here` mapTypeId: google.maps.MapTypeId.ROADMAP, center: copenhagen } map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); directionsDisplay.setMap(map); } var directionsService = new google.maps.DirectionsService(); function calcRoute() { var start = document.getElementById("start").value; var end = document.getElementById("end").value; var distanceInput = document.getElementById("distance"); var request = { origin:start, destination:end, travelMode: google.maps.DirectionsTravelMode.DRIVING }; directionsService.route(request, function(response, status) { if (status == google.maps.DirectionsStatus.OK) { directionsDisplay.setDirections(response); distanceInput.value = response.routes[0].legs[0].distance.value / 1000; } }); } &lt;/script&gt; &lt;title&gt;Distance Calculator&lt;/title&gt; &lt;style type="text/css"&gt; body { font-family:Helvetica, Arial; } #map_canvas { height: 50%; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;body onload="initialize()"&gt; &lt;p&gt;Enter your current location and desired destination to get the distance&lt;/p&gt; &lt;div&gt; &lt;p&gt; &lt;label for="start"&gt;Start: &lt;/label&gt; &lt;input type="text" name="start" id="start" /&gt; &lt;label for="end"&gt;End: &lt;/label&gt; &lt;input type="text" name="end" id="end" /&gt; &lt;input type="submit" value="Calculate Route" onclick="calcRoute()" /&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="distance"&gt;Distance (km): &lt;/label&gt; &lt;input type="text" name="distance" id="distance" readonly="true" /&gt; &lt;/p&gt; &lt;/div&gt; &lt;div id="map_canvas"&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; javascript google geolocation maps </code></pre> <p>I want there to be a click to email link on the link on the page which opens up users email (such as Windows Live Mail on a PC or the Yahoo Mail app on a tablet) and says in the body of the email "Your mileage is ???". I can do this, but I want the mileage to be inputted automatically. I have added in this code in the html section of the script... </p> <pre><code>&lt;p&gt;&lt;a href="mailto:youremail.yahoo.com?subject=Mileage &amp;body=calcRoute('string', 'distance')"&gt;Click to send email&lt;/a&gt;&lt;/p&gt; </code></pre> <p>...and it opens the email but doesn't show the calculated mileage. Instead in the body it shows calcRoute('string, distance'). How do I get it to show the mileage?</p> <p>I understand this question is long but I would appreciate it if you could take the time to answer. It is very important that I get an answer that works as soon as possible. Thank you. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload