/    Sign up×
Community /Pin to ProfileBookmark

How to create price calculator for HTML website

Hi guys,

I’m pretty much new to writing HTML code and was wondering if any of you could help me.
I want to make a very basic price calculator for the rental and delivery of goods for my company.

Basically what it should do is show the total costs, which consist of a fixed part (in this case €70) and a variable part. The variable part is €2 per kilometer, unless the total amount is below €20, then it should be €20.

I made the following in Excel but so far I have been unable to convert it into something that works on my HTML website. The yellow cells should be filled with info from the potential customer.
Screenshot: [url]http://goo.gl/oEpFn1[/url]

Hope to hear from you guys ?!

Cheers

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@cootheadDec 18.2014 — Hi there Chrizzle,

[indent]

and a warm welcome to these forums. ?

Does this help...
[color=navy]
<!DOCTYPE html>
<html lang="en">
<head>

<meta charset="utf-8">

<title>a little calculator</title>

<style media="screen">
body {
background-color:#f0f0f0;
}
#theform {
display:inline-block;
padding:20px;
border:1px solid #666;
border-radius:10px;
background-color:#fff;
color:#666;
box-shadow:inset 0 0 20px #999,3px 3px 3px #666;
}
#theform div {
margin:5px 0;
}
#theform label {
display:inline-block;
width:200px;
}
</style>

<script>
(function() {
'use strict';
var f,d,k;
function init(){
f=document.getElementById('theform');
f.reset();
document.getElementById('calc').onclick=function() {
d=document.getElementById('days').value;
k=document.getElementById('kilo').value;
if(isNaN(d)||d==''||isNaN(k)||k=='') {
f.reset();
alert('please enter a numerical value'); <br/>
return;
}
else {
if(k&lt;10) {
k=20;
}
else {
k=k*2;
}
document.getElementById('tot').value='€ '+parseFloat(d*70+k); <br/>
}
}
}
window.addEventListener?
window.addEventListener('load',init,false):
window.attachEvent('onload',init);
})();
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;form id="theform" action="#"&gt;
&lt;div&gt;
&lt;label for="days"&gt;Amount of days :&lt;/label&gt;
&lt;input id="days" type="text"&gt;
&lt;/div&gt;&lt;div&gt;
&lt;label for="kilo"&gt;Amount of kilometers :&lt;/label&gt;
&lt;input id="kilo" type="text"&gt;
&lt;/div&gt;&lt;div&gt;
&lt;label&gt;Total :&lt;/label&gt;
&lt;input id="tot" type="text" readonly="readonly"&gt;
&lt;/div&gt;&lt;div&gt;
&lt;label&gt;&lt;/label&gt;
&lt;input id="calc" type="button" value="calculate"&gt;
&lt;input id="r" type="reset" value="clear"&gt;
&lt;/div&gt;
&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;[/color]

[/indent]

[i]coothead[/i]
Copy linkTweet thisAlerts:
@NogDogDec 18.2014 — <pedantry>

Note that from the preceding example, HTML itself can't actually [i]do[/i] anything dynamic. In this case, JavaScript [i]code[/i] was embedded within the HTML [I]markup[/I], since HTML itself is not a programming language -- it's "just" a text mark-up specification.

</pedantry>
×

Success!

Help @Chrizzle spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...