ok, i'm a newbie -- but persistent, willing to learn, and usually good at following instructions...
i don't know exactly how to get started with coding this... so i have nothing thus far... looking for beginning ideas.
goal: create a swimming pool party rental calculator for my neighborhood pool
inputs: party begin date and time, party end date and time, # of party people
calculation (this is my biggest hurdle): how to calculate the number of hours during "normal operational hours" and the number of hours "after operational hours". (reason: the cost per hour of the party goes up significantly for an "after hours" pool party)
example:
input party start time: 5/1/2006 6pm
input party end time: 5/2/2006 1am
number in party: 120
somehow? embed information about normal operational hours:
5/1/2006 9am-8pm
5/2/2006 10am-7pm
...and all other normal operational dates and times
Based upon the inputs, needs to return the following:
number of hours during normal operational hours = 2
number of hours after normal operational hours = 5
additional calculations are also necessary, but i think i know how to do those...
the long answer is the schedule is all over the map and looks something like this (this is last years schedule -- this years schedule is not yet made):
May 14-24 M-Th 6:30pm-8pm, F 6:30pm-9pm, Sat 10am-9pm Sun 11am-8pm
May 25-July 8 M-Th 11am-8pm, F 11am-10pm, Sat 10am-9pm, Sun 11am-8pm
July 9-Aug 12 M-Th 10am-8pm, F 10am-10pm, Sat 10am-9pm, Sun 11am-8pm
Aug 11-Aug 21 M-Th 1pm-8pm, F 1pm-9pm, Sat 10am-9pm, Sun 11am-8pm
Aug 22-Sept 11 M-Th 4pm-8pm, F 4pm-8pm, Sat 10am-9pm, Sun 12am-8pm
Special note: Sept 5 (labor day) 10am-10pm
I am aswell a newbie with javascript...But that seems similar to what I was looking for. I wanted to use the "onblur" command to run the javascript...but when I use it, I recieve an error...
Line: 21
Char: 3
Error: 'value' is null or not an object
Code: 0
If i use the submit button, everything works fine...but when i attempt to choose the onblur and use that...It gives me that error.
James -- Again, THANK YOU very very much for trying to help me!!!
i've been studing your example and i have to admit it is pushing my capabilities but i'm trying hard to understand.
best i can tell, the code you provided allows for the same operational time each day and doesn't take into consideration the differing operational times based upon month and day. I'm therefore speculating i need to calculate the number of minutes that makes up the operational time for first part of my schedule as follows.
May 14-24 M-Th 6:30pm-8pm, F 6:30pm-9pm, Sat 10am-9pm Sun 11am-8pm
would look something like this in the code:
Code:
var hrsOp = [];
hrsOp['may14sat'] = [192120,192780]; //min though April 30th + min in 13 days + min to 10am ..... then minutes to 9pm;
hrsOp['may15sun'] = [193620,194160]; //min though April 30th + min in 14 days + min to 11am ..... then minutes to 8pm;
hrsOp['may16mon'] = [195510,195600]; //min though April 30th + min in 15 days + min to 6:30pm ..... then minutes to 8pm;
hrsOp['may17tue'] = [196950,197040]; //min though April 30th + min in 16 days + min to 6:30pm ..... then minutes to 8pm;
hrsOp['may18wed'] = [198390,198480]; //min though April 30th + min in 17 days + min to 6:30pm ..... then minutes to 8pm;
hrsOp['may19thu'] = [199830,199920]; //min though April 30th + min in 18 days + min to 6:30pm ..... then minutes to 8pm;
hrsOp['may20fri'] = [201270,201420]; //min though April 30th + min in 19 days + min to 6:30pm ..... then minutes to 9pm;
hrsOp['may21sat'] = [202200,202860]; //min though April 30th + min in 20 days + min to 10am ..... then minutes to 9pm;
hrsOp['may22sun'] = [203700,204240]; //min though April 30th + min in 21 days + min to 11am ..... then minutes to 8pm;
hrsOp['may23mon'] = [205590,205680]; //min though April 30th + min in 22 days + min to 6:30pm ..... then minutes to 8pm;
hrsOp['may24tue'] = [207030,207120]; //min though April 30th + min in 23 days + min to 6:30pm ..... then minutes to 8pm;
based upon:
number of minutes in Jan (31) = 44640
number of minutes in Feb (28) = 40320 84960
number of minutes in Mar (31) = 44640 129600
number of minutes in Apr (30) = 43200 172800
number of minutes in May (31) = 44640 217440
number of minutes in June (30) = 43200 260640
number of minutes in a day = 1440
then i'm lost on what i need to do below in the code...
can someone tell me if i'm at least on the right track or if there is a simplier way...
i was also hoping the calculations would take place when leaving the fields instead of having to press the calculate/submit button -- can this also be done?
thanks many times over for any help anyone can provide!
i really like the format of having the date, opentime, and closetime the way you suggested -- this will make it easy for even someone like me to edit in the future as the operational dates and times change.
so i'm trying to implement what you have. keep in mind i'm really really green like grasshopper with very little experience in javascripting!!
i tried to show at least some progress and worked on the format and fields that i believe i need and this is where i am -- it gives me an error and i realize i don't really have any formulas in it -- but could use a little more help if possible just to get the basics working...
here is first of two parts (hope this is ok to post it this way...)
Code:
<html>
<head>
<script type="text/javascript">
var schedule = new Object();
schedule.addEntry = addScheduleEntry;
schedule.getEntry = getScheduleEntry;
schedule.addEntry(entryDate="05/14/2006", openTime="06:30", closeTime="20:00");
schedule.addEntry(entryDate="05/15/2006", openTime="06:30", closeTime="20:00");
schedule.addEntry(entryDate="05/16/2006", openTime="06:30", closeTime="20:00");
schedule.addEntry(entryDate="05/17/2006", openTime="06:30", closeTime="20:00");
schedule.addEntry(entryDate="05/18/2006", openTime="06:30", closeTime="21:00");
schedule.addEntry(entryDate="05/19/2006", openTime="10:00", closeTime="21:00");
schedule.addEntry(entryDate="05/20/2006", openTime="11:00", closeTime="20:00");
function addScheduleEntry(entryDate, openTime, closeTime) {
if(typeof entryDate != "string")
{
alert('String Entry Date argument required ("mm/dd/yyyy").');
return false;
}
if(!entryDate.isDate())
{
alert('Entry Date is invalid or incorrectly formatted ("mm/dd/yyyy").');
return false;
}
var objDate = new Date(entryDate);
this[objDate.toUSAdate()] = new Array(convert2Minutes(openTime), convert2Minutes(closeTime));
return true;
}
function getScheduleEntry(entryDate) {
if(typeof entryDate != "string") {
alert('String Entry Date argument required ("mm/dd/yyyy").');
return null;
}
if(!entryDate.isDate()) {
alert('Entry Date is invalid or incorrectly formatted ("mm/dd/yyyy").');
return null;
}
var objDate = new Date(entryDate);
return this[objDate.toUSAdate()];
}
String.prototype.isDate; function() {
// validate that the object string is a valid mm/dd/yyyy date
if(this.toString().isEmpty()) return false;
var delim = (arguments.length>0) ? arguments[0] : "/";
delim = (typeOf(delim)=="string" && delim.length>0) ? delim : "/";
var dte = new Date(this.toString());
var ary = this.toString().split(delim);
for (var i in ary) { ary[i] = new Number(ary[i]); }
if(ary.length != 3
|| ary[0] != (dte.getMonth()+1)
|| ary[1] != dte.getDate()
|| ary[2] != dte.getFullYear() ) {
return false;
}
return true;
}
Date.prototype.toUSAdate = function() {
var str;
return (str="0"+(this.getMonth()+1)).substr(str.length-2) + "/" +
(str="0"+this.getDate()).substr(str.length-2) + "/" +
(str="000"+this.getFullYear()).substr(str.length-4)
}
function convert2Minutes(str24hrTime) {
if(typeof str24hrTime != "string") {
alert('String Time argument required ("hh:mm").');
return 0;
}
var ary = str24hrTime.split(":");
if(ary.length != 2) {
alert('Hours and Minutes must be delimited with a colon (":").');
return 0;
}
ary[0] = Number(ary[0]);
if(isNaN(ary[0])
|| ary[0] < 0
|| ary[0] > 23) {
alert('Hours are not numeric or are out of range.');
return 0;
}
ary[1] = Number(ary[1]);
if(isNaN(ary[1])
|| ary[1] < 0
|| ary[1] > 59) {
alert('Minutes are not numeric or are out of range.');
return 0;
}
return ary[1] + (ary[0]*60);
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Pool Rental Calculator</title>
</head>
<body>
<table border="0" cellspacing="0" width="100%" cellpadding="4">
<tr>
<td width="97%" height="38" align="right" valign="top" colspan="5">
</td>
</tr>
<tr>
<td width="21%" height="28" align="right" valign="top"> </td>
<td width="76%" height="28" valign="bottom" style="font-family: aria; font-size: 10pt; font-style: italic" colspan="4"> </td>
</tr>
<tr>
<td width="21%" height="28" align="right" valign="top"><b>
<font size="4">Party Details</font></b></td>
<td width="76%" height="28" valign="bottom" style="font-family: aria; font-size: 10pt; font-style: italic" colspan="4">
<font size="2">
Please enter the details of your party below to calculate an automatic
price quote:</font></td>
</tr>
<tr>
<td width="21%" height="28" align="right" valign="top"><font size="2">
Start Information:</font></td>
<td width="76%" height="28" valign="bottom" style="font-family: aria; font-size: 10pt; font-style: italic" colspan="4">
Date (mm/dd/yyyy):
<input type="text" name="startdate" size="13" onblur='validhours()'>
Time (x:xx am or x:xx pm):
<input type="text" name="starttime" size="9"></td>
</tr>
<tr>
<td width="21%" height="28" align="right" valign="top"><font size="2">
End Information:</font></td>
<td width="76%" height="28" valign="bottom" style="font-family: aria; font-size: 10pt; font-style: italic" colspan="4">
Date (mm/dd/yyyy):
<input type="text" name="enddate" size="13" onblur='validhours()'>
Time (x:xx am or x:xx pm):
<input type="text" name="endtime" size="9"></td>
</tr>
<tr>
<td width="21%" height="28" align="right" valign="top"><font size="2">
Number of Attendees:</font></td>
<td width="29%" height="28" valign="bottom" style="font-family: aria; font-size: 10pt; font-style: italic">
Quantity:
<input type="text" name="quantity" size="13"> </td>
<td width="66%" height="28" valign="bottom" style="font-family: aria; font-size: 10pt; font-style: italic" colspan="3">
(according to County regulations, must include total quantity of
attendees both in the pool and on the deck)</td>
</tr>
<tr>
<td width="21%" height="28" align="right" valign="top"><font size="2">
Include Clubhouse Rental:</font></td>
<td width="76%" height="28" valign="bottom" style="font-family: aria; font-size: 10pt; font-style: italic" colspan="4">
<input type="radio" value="V1" name="clubrent" onBlur='valid(this.form)'>Yes
<input type="radio" value="V2" name="clubrent" onBlur='valid(this.form)' checked>No
Are you a current member of the pool:
<input type="radio" value="V1" name="currentmember" onBlur='valid(this.form)'>Yes
<input type="radio" value="V2" name="currentmember" onBlur='valid(this.form)' checked>No </td>
</tr>
<tr>
<td width="21%" height="28" align="right" valign="top"> </td>
<td width="76%" height="28" valign="bottom" style="font-family: aria; font-size: 10pt; font-style: italic" colspan="4"> </td>
</tr>
<tr>
<td width="21%" height="28" align="right" valign="top"> </td>
<td width="43%" height="28" valign="bottom" style="font-family: aria; font-size: 10pt; font-style: italic" colspan="2"> </td>
<td width="14%" height="28" valign="bottom" style="font-family: aria; font-size: 10pt; font-style: italic"> </td>
<td width="16%" height="28" valign="bottom" style="font-family: aria; font-size: 10pt; font-style: italic"> </td>
</tr>
<tr>
<td width="21%" height="28" align="right" valign="top"><font size="4">
<b>Rental Price Quote</b></font></td>
<td width="43%" height="28" valign="bottom" style="font-family: aria; font-size: 10pt; font-style: italic" colspan="2"> </td>
<td width="14%" height="28" valign="bottom" style="font-family: aria; font-size: 10pt; font-style: italic"> </td>
<td width="16%" height="28" valign="bottom" style="font-family: aria; font-size: 10pt; font-style: italic"> </td>
</tr>
</table>
<table border="1" cellspacing="0" width="100%" cellpadding="4" id="table2" bordercolor="#000000">
<tr>
<td width="21%" height="28" align="right" valign="top" bordercolor="#000000"> </td>
<td width="43%" height="28" valign="bottom" style="font-family: aria; font-size: 10pt; font-style: italic" bordercolor="#000000"> </td>
<td width="14%" height="28" valign="bottom" style="font-family: aria; font-size: 10pt; font-style: italic" bordercolor="#000000">
Rate per unit</td>
<td width="16%" height="28" valign="bottom" style="font-family: aria; font-size: 10pt; font-style: italic" bordercolor="#000000">
Sub-Total</td>
</tr>
<tr>
Bookmarks