...

View Full Version : Help trying to make a times to money calculator



rowl3y
08-21-2010, 11:01 AM
Hi all this is my first post here. Found this place by google :D

Well basically i have coded a java script well edited from here i think.

This is the page at the moment
http://rowleysdiscos.co.uk/instant.php

but I'm trying to edit to i have drop down boxes with

Start

6:00
6:30
7:00
7:30
8:00
8:30

End

10:00
10:30
11:30
12:00
12:30
01:00
01:30

Then the same for karaoke start and finish.

But the hard part it getting the right

So minium booking is 2 hours for 100 and then every hour after is 30 and 15 for 30 Min's karaoke is 5 an hour .

i have look and tried everythink but just cart get it to work

hope some one can help me

Dave

Fou-Lu
08-21-2010, 05:34 PM
Despite the similar sounding names, Java is not the same as Javascript.
Moving from the Java forum to the Javascript forum.

Philip M
08-21-2010, 06:44 PM
As Fou-Lu has pointed out, Java and Javascript are entirely different programming languages, in spite of the confusingly similar names. Java is NOT short for JavaScript!

This should move you forward:-



<form name = "myform">
START TIME <select name = "startTime">
<option value = "6" selected>6.00</option>
<option value = "6.5">6.30</option>
<option value = "7">7.00</option>
<option value = "7.5">7.30</option>
<option value = "8">8.00</option>
<option value = "8.5">8.30</option>
</select>

END TIME <select name = "endTime">
<option value = "10" selected>10.00</option>
<option value = "10.5">10.30</option>
<option value = "11">11.00</option>
<option value = "11.5">11.30</option>
<option value = "12">12.00</option>
<option value = "12.5">12.30</option>
<option value = "13">1.00</option>
<option value = "13.5">1.30</option>
</select>

<br><br>

<input type = "button" value = "Calculate Booking Cost" onclick = "calc()">
<br><br>
<span id = "result"></span>
</form>


<script type = "text/javascript">

function calc() {
var st = document.myform.startTime.value;
var et = document.myform.endTime.value;
var hours = et - st;
alert ("Hours = " + hours); // for testing
if (hours <2) {hours = 2} // minimum 2 hours
var extraHours = hours - 2; // hours over 2
var cost = 100 + (extraHours *30); // at 30 per hour
document.getElementById("result").innerHTML = "The cost of the booking is " + cost;
}

</script>

Note how the value (not the text) of the start and end times is expressed as fractions of an hour (not minutes) and 01.00 is expressed 13 hours (not 1) to make the subtractions simple.

Presumably you can do the same to work out the cost for karaoke.

If a booking can be made for two hours, why is the last start time 8.30 rather than 11.30?

Quizmaster: Which popular pizza, that shares its name with a famous work by Vivaldi, is normally divided into four sections, each containing different toppings??
Contestant: Four cheeses.

rowl3y
08-22-2010, 12:52 AM
Thanks i will take a look at it now thanks ..



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum