What's new
HTML Forums | An HTML and CSS Coding Community

Welcome to HTMLForums; home of web development discussion! Please sign in or register your free account to get involved. Once registered you will be able to connect with other members, send and receive private messages, reply to topics and create your very own. Our registration process is hassle-free and takes no time at all!

HTLM code for calculate distance

Brecht B

New member
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
 
Back
Top