What's new

Welcome to the forum 👋, Visitor

To access the forum content and all our services, you must register or log in to the forum. Becoming a member of the forum is completely free.

HTLM code for calculate distance

Brecht B

New member
Joined
May 21, 2020
Messages
1
Reaction score
0
HTML Coins
0
Hi,

I want on my website a HTML code that calculate the distance from my place (still the same, can be filled in automaticaly) to a place the user choose.
These distance we need to multiply with 1 euro.
BUT: if the distance is 30 km or less, it is for free.
If the distance is more than 30 km, only the km above 30 we need to multiply with 1 euro.

Can somebody help me?

Thanks a lot.
 
Try this code:-
<html>
<head>
</head>
<body>
<h3>Find Distance Between Two Points</h3>
<p><h4>General Formula :</h4></p>
<img src="moomoomath.com/distanc png" width=200px alt="Image Not Available"/>
<p>Enter points x1,x2 and y1,y2</p>
<label>Point X1 :</label>
<br>
<input id="p1" type="number" placeholder="Enter x1">
<br>
<label>Point X2 :</label>
<br>
<input id="p2" type="number" placeholder="Enter x2">
<br>
<label>Point Y1 :</label>
<br>
<input id="p3" type="number" placeholder="Enter y1">
<br>
<label>Point Y2 :</label>
<br>
<input id="p4" type="number" placeholder="Enter y2">
<br>
<br>
<button onclick="calc();">DISTANCE :</button>
<br>
<br>
<div id="output"></div>
</body>
</html>

Hope it helps.

Apps4Rent | O365CloudExperts | CloudDesktopOnline
 
Try this:

function calculateDistance() {
var pointx1 = parseInt(document.getElementById("pointx1").value);
var pointy1 = parseInt(document.getElementById("pointy1").value);
var pointx2 = parseInt(document.getElementById("pointx2").value);
var pointy2 = parseInt(document.getElementById("pointy2").value);

var distance = Math.sqrt(Math.pow((pointx1-pointx2),2)+Math.pow((pointy1-pointy2),2));

window.alert("Distance: "+distance);
}
<form name = "f1" method="post">
<label>Point 1:</label><br>
x:<input type = "text" id = "pointx1" size = "30"/> &nbsp; y1:<input type = "text" id = "pointy1" size = "30"/>
<br>
<label>Point 2:</label> <br>
x:<input type = "text" id = "pointx2" size = "30"/> &nbsp; y2:<input type = "text" id = "pointy2" size = "30"/>
<button onclick = "calculateDistance(); return false;">Calculate Distance</button>
</form>

Let me know if it works.

Regards,
Tony
 

Theme customization system

You can customize some areas of the forum theme from this menu.

  • Wide/Narrow view

    You can control a structure that you can use to use your theme wide or narrow.

    Grid view forum list

    You can control the layout of the forum list in a grid or ordinary listing style structure.

    Picture grid mode

    You can control the structure where you can open/close images in the grid forum list.

    Close sidebar

    You can get rid of the crowded view in the forum by closing the sidebar.

    Fixed sidebar

    You can make it more useful and easier to access by pinning the sidebar.

    Close radius

    You can use the radius at the corners of the blocks according to your taste by closing/opening it.

  • Choose the color combination that reflects your taste
    Background images
    Color gradient backgrounds
Back