bagni99
asked on
Calculate Time Difference in Minutes -then divide by time unit
Hi All,
I have 5 fields:
START TIME END TIME TOTAL TIME TIME UNIT TOTAL UNITS
What I need is to calculate the difference in time (in minutes) between the START TIME and the END TIME. Then divide the minutes by the TIME UNIT (which default is 15 but can be changed). The result is then to be put in the TOTAL UNITS field.
So if
START TIME END TIME TOTAL TIME TIME UNIT TOTAL UNITS
10:00 11:00 60 15 4
I don't really need the TOTAL TIME field and would like to discard it if possible. The TIME UNIT will probably be a hidden field.
I currently have been using the following Javascript to calculate the time in hours and minutes.
<script language=javascript>
function calculate(){
var start = document.getElementById("x _os_startt ime").valu e.split(': ');
var end = document.getElementById("x _os_endtim e").value. split(':') ;
var total = document.getElementById("x _os_totalt ime");
var shour = parseInt(start[0].substrin g(0,1)== '0'? start[0].substring(1):star t[0]);
var smin = parseInt(start[1]);
var ehour = parseInt(end[0].substring( 0,1)== '0'? end[0].substring(1):end[0] );
var emin = parseInt(end[1]);
if (shour>ehour)
alert("error");
else if (shour == ehour)
total.value = "00:"+(emin-smin);
else{
if (emin>=smin)
total.value=(ehour-shour)+ ":"+(emin- smin);
else
total.value=(ehour-shour-1 )+":"+(60- smin+emin) ;
}
}
</script>
The function is called by an onChange="calculate()" which is attached to the END TIME field.
I am not sure how to change the code to calculate in minutes then divide by the TIME UNIT. Can anyone help me?
I did find that someone had asked the 'minute calculation' question before but the answer was a dead link to another website.
Better code ideas are welcomed.
Bagni99
I have 5 fields:
START TIME END TIME TOTAL TIME TIME UNIT TOTAL UNITS
What I need is to calculate the difference in time (in minutes) between the START TIME and the END TIME. Then divide the minutes by the TIME UNIT (which default is 15 but can be changed). The result is then to be put in the TOTAL UNITS field.
So if
START TIME END TIME TOTAL TIME TIME UNIT TOTAL UNITS
10:00 11:00 60 15 4
I don't really need the TOTAL TIME field and would like to discard it if possible. The TIME UNIT will probably be a hidden field.
I currently have been using the following Javascript to calculate the time in hours and minutes.
<script language=javascript>
function calculate(){
var start = document.getElementById("x
var end = document.getElementById("x
var total = document.getElementById("x
var shour = parseInt(start[0].substrin
var smin = parseInt(start[1]);
var ehour = parseInt(end[0].substring(
var emin = parseInt(end[1]);
if (shour>ehour)
alert("error");
else if (shour == ehour)
total.value = "00:"+(emin-smin);
else{
if (emin>=smin)
total.value=(ehour-shour)+
else
total.value=(ehour-shour-1
}
}
</script>
The function is called by an onChange="calculate()" which is attached to the END TIME field.
I am not sure how to change the code to calculate in minutes then divide by the TIME UNIT. Can anyone help me?
I did find that someone had asked the 'minute calculation' question before but the answer was a dead link to another website.
Better code ideas are welcomed.
Bagni99
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I have tried it with 10:00 and 11:00 and it outputs 4 as expected. The time units is 15, set in a hidden form field that you can change. I've tried in both FF2 and IE7, and it should work in previous versions as well.
ASKER
Thanks again.
Thanks for your patience.
You have done exactly what I have asked.
I know what the problem is....it's to do with something I failed to tell you.
The TIME UNITS field (that can be changed) is actually a combo box. So the default is 15 but it's value is 1. Figure that is why the time units equals the same as the minutes.
I'll double the points if you can tell me if there is a way for you to use the number in the combo box as opposed to the value.
Thanks again,
bagni99
Thanks for your patience.
You have done exactly what I have asked.
I know what the problem is....it's to do with something I failed to tell you.
The TIME UNITS field (that can be changed) is actually a combo box. So the default is 15 but it's value is 1. Figure that is why the time units equals the same as the minutes.
I'll double the points if you can tell me if there is a way for you to use the number in the combo box as opposed to the value.
Thanks again,
bagni99
You only need to change
var units = Math.floor(minutes / parseInt(frm.x_os_timeunit s.value));
to
var timeunits = parseInt(frm.x_os_timeunit s.options[ frm.x_os_t imeunits.s electedInd ex].value) ;
var units = Math.floor(minutes / timeunits);
var units = Math.floor(minutes / parseInt(frm.x_os_timeunit
to
var timeunits = parseInt(frm.x_os_timeunit
var units = Math.floor(minutes / timeunits);
ASKER
I've just tried changing the code - I haven't got it working yet. I don't have the time to work out what I have done wrong right now....I'll have a look later today. Thanks again, I'll get back to you soon.
You have to make sure that your <select> dropdown is in between the <form> tags, and that its name is x_os_timeunits
ASKER
Sorry for the delay.
I've been flat out with work and the damn internet has been playing up (I am in East Timor at the moment).
I have got the code working but it seems to still be using the value (1) not the number that is entered (15). The client requires the option to change the number as required..maybe to 20 time units or 30. The value probably wont ever change from 1.
Unsure where to go from here. I'll keep trying other things.
I've been flat out with work and the damn internet has been playing up (I am in East Timor at the moment).
I have got the code working but it seems to still be using the value (1) not the number that is entered (15). The client requires the option to change the number as required..maybe to 20 time units or 30. The value probably wont ever change from 1.
Unsure where to go from here. I'll keep trying other things.
What is your current code?
ASKER
<script type="text/javascript">
<!--
function calculate(frm) {
var start = new Date();
var end = new Date();
//create the start and end dates
var startPieces = frm.x_os_starttime.value.s plit(':');
var endPieces = frm.x_os_endtime.value.spl it(':');
start.setHours(parseInt(st artPieces[ 0]), parseInt(startPieces[1]) % 60);
end.setHours(parseInt(endP ieces[0]), parseInt(endPieces[1]) % 60);
if (start > end) {
alert('Start time must less than end time.');
return false;
}
var difference = end - start;
var minutes = difference / 60000;
var timeunits = parseInt(frm.x_os_timeunit s.options[ frm.x_os_t imeunits.s electedInd ex].value) ;
var units = Math.floor(minutes / timeunits);
frm.x_os_totalunits.value = units;
}
function pad(txt, ch, sz, dir) {
if (arguments.length < 4) {
dir = 'left'
}
txt = txt.toString(); ch = ch.toString();
var numchars = Math.floor((sz - txt.length) / ch.length);
if (dir == 'left') {
for (var i = 0; i < numchars; i++) {
txt = ch + txt;
}
} else {
for (var i = 0; i < numchars; i++) {
txt += ch;
}
}
return txt;
}
//-->
</script>
.............
<form name="foccasion_of_service add" id="foccasion_of_servicead d" action="occasion_of_servic eadd.asp" method="post" onSubmit="return EW_checkMyForm(this);">
..............
<tr>
<td class="ewTableHeader"><spa n>Start Time</span></td>
<td class="ewTableAltRow"><spa n id="cb_x_os_starttime">
<input type="text" name="x_os_starttime" id="x_os_starttime" size="12" value="<% If IsDate(x_os_starttime) Then Response.Write EW_FormatDateTime(x_os_sta rttime,4) Else Response.Write x_os_starttime End If %>">
</span></td>
</tr>
<tr>
<td class="ewTableHeader"><spa n>End Time</span></td>
<td class="ewTableAltRow"><spa n id="cb_x_os_endtime">
<input type="text" name="x_os_endtime" id="x_os_endtime" size="12" value="<% If IsDate(x_os_endtime) Then Response.Write EW_FormatDateTime(x_os_end time,4) Else Response.Write x_os_endtime End If %>">
</span></td>
</tr>
<tr>
<td class="ewTableHeader"><spa n>Total Units</span></td>
<td class="ewTableAltRow"><spa n id="cb_x_os_totalunits">
<% If IsNull(x_os_totalunits) or x_os_totalunits = "" Then x_os_totalunits = 0 ' Set default value %>
<input type="text" name="x_os_totalunits" id="x_os_totalunits" size="5" value="<%= Server.HTMLEncode(x_os_tot alunits&"" ) %>">
</span><input type="button" value="Calculate" onclick="calculate(this.fo rm);"></td >
</tr>
<tr>
<td class="ewTableHeader"><spa n>os timeunits</span></td>
<td class="ewTableAltRow"><spa n id="cb_x_os_timeunits">
<% If IsNull(x_os_timeunits) or x_os_timeunits = "" Then x_os_timeunits = 1 ' Set default value %>
<%
lst_x_os_timeunits = "<select id='x_os_timeunits' name='x_os_timeunits'>"
lst_x_os_timeunits = lst_x_os_timeunits & "<option value=''>Please Select</option>"
sSqlWrk = "SELECT [timeunit_id], [timeunit_value] FROM [timeunit]"
If x_os_timeunits = "" Or IsNull(x_os_timeunits) Then
sSqlWrk = sSqlWrk & " WHERE 0=1"
Else
sSqlWrk = sSqlWrk & " WHERE [timeunit_id] = " & AdjustSql(x_os_timeunits) & ""
End If
Set rswrk = Server.CreateObject("ADODB .Recordset ")
rswrk.Open sSqlWrk, conn
If Not rswrk.Eof Then
datawrk = rswrk.GetRows
rowswrk = UBound(datawrk, 2)
For rowcntwrk = 0 To rowswrk
lst_x_os_timeunits = lst_x_os_timeunits & "<option value='" & datawrk(0, rowcntwrk) & "'"
If CStr(datawrk(0, rowcntwrk)&"") = CStr(x_os_timeunits&"") Then
lst_x_os_timeunits = lst_x_os_timeunits & " selected"
End If
lst_x_os_timeunits = lst_x_os_timeunits & ">" & datawrk(1, rowcntwrk) & "</option>"
Next
End If
rswrk.Close
Set rswrk = Nothing
lst_x_os_timeunits = lst_x_os_timeunits & "</select>"
Response.Write lst_x_os_timeunits
sSqlWrk = "SELECT [timeunit_id], [timeunit_value] FROM [timeunit]"
sSqlWrk = EW_Encode(TEAencrypt(sSqlW rk, EW_RANDOM_KEY))
%>
<input type="hidden" name="s_x_os_timeunits" value="<%= sSqlWrk %>">
<input type="hidden" name="lc_x_os_timeunits" value="2">
<input type="hidden" name="ld1_x_os_timeunits" value="1">
<input type="hidden" name="ld2_x_os_timeunits" value="-1">
</span><input type="button" value="Calculate" onclick="calculate(this.fo rm);"></td >
</tr>
</table>
<p>
<input type="submit" name="btnAction" id="btnAction" value="ADD">
</form>
<!--
function calculate(frm) {
var start = new Date();
var end = new Date();
//create the start and end dates
var startPieces = frm.x_os_starttime.value.s
var endPieces = frm.x_os_endtime.value.spl
start.setHours(parseInt(st
end.setHours(parseInt(endP
if (start > end) {
alert('Start time must less than end time.');
return false;
}
var difference = end - start;
var minutes = difference / 60000;
var timeunits = parseInt(frm.x_os_timeunit
var units = Math.floor(minutes / timeunits);
frm.x_os_totalunits.value = units;
}
function pad(txt, ch, sz, dir) {
if (arguments.length < 4) {
dir = 'left'
}
txt = txt.toString(); ch = ch.toString();
var numchars = Math.floor((sz - txt.length) / ch.length);
if (dir == 'left') {
for (var i = 0; i < numchars; i++) {
txt = ch + txt;
}
} else {
for (var i = 0; i < numchars; i++) {
txt += ch;
}
}
return txt;
}
//-->
</script>
.............
<form name="foccasion_of_service
..............
<tr>
<td class="ewTableHeader"><spa
<td class="ewTableAltRow"><spa
<input type="text" name="x_os_starttime" id="x_os_starttime" size="12" value="<% If IsDate(x_os_starttime) Then Response.Write EW_FormatDateTime(x_os_sta
</span></td>
</tr>
<tr>
<td class="ewTableHeader"><spa
<td class="ewTableAltRow"><spa
<input type="text" name="x_os_endtime" id="x_os_endtime" size="12" value="<% If IsDate(x_os_endtime) Then Response.Write EW_FormatDateTime(x_os_end
</span></td>
</tr>
<tr>
<td class="ewTableHeader"><spa
<td class="ewTableAltRow"><spa
<% If IsNull(x_os_totalunits) or x_os_totalunits = "" Then x_os_totalunits = 0 ' Set default value %>
<input type="text" name="x_os_totalunits" id="x_os_totalunits" size="5" value="<%= Server.HTMLEncode(x_os_tot
</span><input type="button" value="Calculate" onclick="calculate(this.fo
</tr>
<tr>
<td class="ewTableHeader"><spa
<td class="ewTableAltRow"><spa
<% If IsNull(x_os_timeunits) or x_os_timeunits = "" Then x_os_timeunits = 1 ' Set default value %>
<%
lst_x_os_timeunits = "<select id='x_os_timeunits' name='x_os_timeunits'>"
lst_x_os_timeunits = lst_x_os_timeunits & "<option value=''>Please Select</option>"
sSqlWrk = "SELECT [timeunit_id], [timeunit_value] FROM [timeunit]"
If x_os_timeunits = "" Or IsNull(x_os_timeunits) Then
sSqlWrk = sSqlWrk & " WHERE 0=1"
Else
sSqlWrk = sSqlWrk & " WHERE [timeunit_id] = " & AdjustSql(x_os_timeunits) & ""
End If
Set rswrk = Server.CreateObject("ADODB
rswrk.Open sSqlWrk, conn
If Not rswrk.Eof Then
datawrk = rswrk.GetRows
rowswrk = UBound(datawrk, 2)
For rowcntwrk = 0 To rowswrk
lst_x_os_timeunits = lst_x_os_timeunits & "<option value='" & datawrk(0, rowcntwrk) & "'"
If CStr(datawrk(0, rowcntwrk)&"") = CStr(x_os_timeunits&"") Then
lst_x_os_timeunits = lst_x_os_timeunits & " selected"
End If
lst_x_os_timeunits = lst_x_os_timeunits & ">" & datawrk(1, rowcntwrk) & "</option>"
Next
End If
rswrk.Close
Set rswrk = Nothing
lst_x_os_timeunits = lst_x_os_timeunits & "</select>"
Response.Write lst_x_os_timeunits
sSqlWrk = "SELECT [timeunit_id], [timeunit_value] FROM [timeunit]"
sSqlWrk = EW_Encode(TEAencrypt(sSqlW
%>
<input type="hidden" name="s_x_os_timeunits" value="<%= sSqlWrk %>">
<input type="hidden" name="lc_x_os_timeunits" value="2">
<input type="hidden" name="ld1_x_os_timeunits" value="1">
<input type="hidden" name="ld2_x_os_timeunits" value="-1">
</span><input type="button" value="Calculate" onclick="calculate(this.fo
</tr>
</table>
<p>
<input type="submit" name="btnAction" id="btnAction" value="ADD">
</form>
Is it possible to only get the form from the generated HTML (browser View Source)? I don't see anything wrong taking a look at this code--it seems perfectly fine, but the generated code might provide clues easier to discern.
ASKER
Here's the whole form. Thanx
<form name="foccasion_of_service add" id="foccasion_of_servicead d" action="occasion_of_servic eadd.asp" method="post" onSubmit="return EW_checkMyForm(this);">
<p>
<input type="hidden" name="a_add" value="A">
<table class="ewTable">
<tr>
<td class="ewTableHeader"><spa n>Date</sp an></td>
<td class="ewTableAltRow"><spa n id="cb_x_os_date">
<input type="text" name="x_os_date" id="x_os_date" size="12" value="">
<img src="images/ew_calendar.gi f" id="cx_os_date" alt="Pick a date" style="cursor:pointer;curs or:hand;">
<script type="text/javascript">
Calendar.setup(
{
inputField : "x_os_date", // ID of the input field
ifFormat : "%d/%m/%Y", // the date format
button : "cx_os_date" // ID of the button
}
);
</script>
</span></td>
</tr>
<tr>
<td class="ewTableHeader"><spa n>Health Professional</span></td>
<td class="ewTableAltRow"><spa n id="cb_x_hp_id">
<select id='x_hp_id' name='x_hp_id'><option value=''>Please Select</option></select>
<input type="hidden" name="s_x_hp_id" value="B%1B%C3%99%2Fwo%C2% 90!33!%C3% 9C%2B%C2%B 7X%C3%AEc% C2%B4VQ%06 %C3%B6%C3% A2%17%C2%9 D%C2%BC7%C 2%9F%C3%B8 u%C3%95%C2 %BE%15(%C3 %87%C2%96b %C3%B0%C3% AA%C3%A8%C 2%84%C3%B8 %C3%ADe%C3 %89W%C3%B3 %C3%AA%C3% A8t.akR%C3 %8C%40%C2% 94%1Do%C2% A9%C2%9F9C %C3%B6D%09 %C2%9E%C3% 92%C2%AC%C 3%B4S%10%C 2%A7%3C%C2 %B8%C2%A3% C2%85%C2%B F%3A%C3%91 4%C2%93%24 %C2%92%C2% AE%17%C3%9 2%C2%9D%2F %C3%8D%13% C2%AEV2%C3 %A1%C3%A2% 1CSN%05%23 %3FW%C3%9C %60%C3%8E% C3%93h%C2% 9F%C2%A8%C 2%A4%C3%85 %09u%3Dv%C 3%AD%C3%A3 -%C3%A8%09 %C2%9B%C3% 86U%C3%A9L %C2%A2">
<input type="hidden" name="lc_x_hp_id" value="3">
<input type="hidden" name="ld1_x_hp_id" value="1">
<input type="hidden" name="ld2_x_hp_id" value="2">
</span></td>
</tr>
<tr>
<td class="ewTableHeader"><spa n>Venue</s pan></td>
<td class="ewTableAltRow"><spa n id="cb_x_venue_id">
<select id='x_venue_id' name='x_venue_id'><option value=''>Please Select</option></select>
<input type="hidden" name="s_x_venue_id" value="%C3%B0!33!%C2%88%C3 %8A%3A%C2% ADN%C3%B8x p%C2%9D%C3 %B7%C3%8B% C2%96%C3%8 2)!0!%C3%A 8V%17%C3%9 DNnX%C3%B5 %C2%B2v%1A %C3%99%C2% 85%C2%85%2 B.%C3%94f% C2%A0%22%C 2%8Dc8%40% C3%B8k%7Bp %C2%9E%3CE R%C2%84%C2 %B1%C3%AD% C3%AC%C3%A 9%C2%86%C3 %A0f%C2%9E %C3%AA%C2% BC%C2%B7%6 01%C3%A8%C 2%94%3D6k% C2%87%03%C 2%BFt%20y% C2%A9%C2%A 7%C2%AE%09 Q%C3%9C%16 %C3%983K%3 E~%C3%BE%0 3%C2%9D%C3 %97%C2%8D% C2%9A%C3%B B%C3%8EW4k %25%C2%9A% C3%94">
<input type="hidden" name="lc_x_venue_id" value="2">
<input type="hidden" name="ld1_x_venue_id" value="1">
<input type="hidden" name="ld2_x_venue_id" value="-1">
</span></td>
</tr>
<tr>
<td class="ewTableHeader"><spa n>New or FUP</span></td>
<td class="ewTableAltRow"><spa n id="cb_x_client_status">
<table class="aspmakerlist"><tr>< td>
<input type="radio" name="x_client_status" checked value="1">
New</td><td>
<input type="radio" name="x_client_status" value="2">
FUP</td><td> </td><td > </t d><td>&nbs p;</td></t r></table>
</span></td>
</tr>
<tr>
<td class="ewTableHeader"><spa n>Client Type</span></td>
<td class="ewTableAltRow"><spa n id="cb_x_os_clienttype">
<table class="aspmakerlist"><tr>< td>
<input type="radio" name="x_os_clienttype" checked value="1">
Ind</td><td>
<input type="radio" name="x_os_clienttype" value="2">
Grp</td><td> </td><td > </t d><td>&nbs p;</td></t r></table>
</span></td>
</tr>
<tr>
<td class="ewTableHeader"><spa n>Client</ span></td>
<td class="ewTableAltRow"><spa n id="cb_x_client_id">
<select id='x_client_id' name='x_client_id'><option value=''>Please Select</option></select>
<input type="hidden" name="s_x_client_id" value="%C2%85%C3%8E%C2%93% C3%82%2F%C 3%89%0F%24 Q%05%C2%92 3j%C2%B4%C 3%BE%C3%A9 D%C3%8AJ%1 4%C3%99!33 !%C3%80%C2 %BAL1%C3%9 4%17%C2%86 %C3%9B%C2% 85%C3%BB%C 3%A6%C2%A2 %C3%B4%C3% BA!12!!13! %C3%BE%C2% B7%3A%C3%B Em%C3%99%2 5%22%C2%8A e%C2%97%C2 %B8%C3%B2% C3%B56%C3% A1N%C3%B1% C2%AD%C2%A 8%20%C2%9F %C2%B4%15% C3%B8S%C2% A3D%20%C2% B0%1D%1Bg% C2%93F%C3% 9C%03G%C3% 9D%C3%85R2 %C3%BB%C2% 98%C3%A1%C 2%8B%C3%B7 %2CA%7F%C3 %A4B%C3%96 %C2%B6%C2% B8h(%08%C3 %81-%C2%9B %25%C3%B0% C3%98!33!) %C3%83H%C2 %A5%C3%92% 01F%C3%BE4 n%2C5%3Dbv %C3%B8%C3% 82">
<input type="hidden" name="lc_x_client_id" value="3">
<input type="hidden" name="ld1_x_client_id" value="1">
<input type="hidden" name="ld2_x_client_id" value="2">
</span></td>
</tr>
<tr>
<td class="ewTableHeader"><spa n>Group Client</span></td>
<td class="ewTableAltRow"><spa n id="cb_x_grpclient_id">
<select id='x_grpclient_id' name='x_grpclient_id'><opt ion value=''>Please Select</option></select>
<input type="hidden" name="s_x_grpclient_id" value="G%60%C2%AE*%C3%96%C 2%B8%C3%9B f%C3%A6%C3 %95%C3%AF% C2%B6!12!8 %1A%C3%A3K %C2%97%02! 0!%08%1A.i %7F%C3%82% C3%9F%C2%8 Az%C2%81%C 2%9C%C2%93 %C2%86hXm% C3%B9%C3%9 A%1A%C2%9B %22%C2%AC% C2%86%1C%0 7%C2%BCE%5 D%C3%86%C2 %91%C2%9AJ %18%1A%C3% 9BH'%C2%AA Z%C2%BA%C3 %BC%C2%B0% C2%BE%C3%A 4%3B%60%C3 %B1%C2%99% 20%C3%8E%C 2%B1%C3%8D %0E%C3%93% C2%8E%16%C 3%93%2F%C2 %98%C2%BF% 1E%C2%9D%0 1%C2%99w%C 3%A4%C2%84 %C2%A2%C3% 91V%10%C2% B4%C3%96%C 2%939%C2%8 C%08%C2%B8 %C2%BB%C3% 90AZ%C2%9A %C3%B8%C2% AE%C3%8D9t ">
<input type="hidden" name="lc_x_grpclient_id" value="2">
<input type="hidden" name="ld1_x_grpclient_id" value="1">
<input type="hidden" name="ld2_x_grpclient_id" value="-1">
</span></td>
</tr>
<tr>
<td class="ewTableHeader"><spa n>Start Time</span></td>
<td class="ewTableAltRow"><spa n id="cb_x_os_starttime">
<input type="text" name="x_os_starttime" id="x_os_starttime" size="12" value="">
</span></td>
</tr>
<tr>
<td class="ewTableHeader"><spa n>End Time</span></td>
<td class="ewTableAltRow"><spa n id="cb_x_os_endtime">
<input type="text" name="x_os_endtime" id="x_os_endtime" size="12" value="">
</span></td>
</tr>
<tr>
<td class="ewTableHeader"><spa n>Total Units</span></td>
<td class="ewTableAltRow"><spa n id="cb_x_os_totalunits">
<input type="text" name="x_os_totalunits" id="x_os_totalunits" size="5" value="0">
</span><input type="button" value="Calculate" onclick="calculate(this.fo rm);"></td >
</tr>
<tr>
<td class="ewTableHeader"><spa n>os timeunits</span></td>
<td class="ewTableAltRow"><spa n id="cb_x_os_timeunits">
<select id='x_os_timeunits' name='x_os_timeunits'><opt ion value=''>Please Select</option><option value='1' selected>15</option></sele ct>
<input type="hidden" name="s_x_os_timeunits" value="0t%C3%A048%0EM%1B%0 EM%C3%B8%C 3%93%5C(%C 2%9A%C3%9F %C3%84m!11 !%10%C2%9A s%3D%C2%96 %3B%C3%8B% C2%9F%3D%C 3%80.%C2%9 E%C3%8B%1E n%C2%99%2B (%C2%95%09 %5B(w%C2%9 A%C2%A5L%0 2%C2%A2%3C %C3%94%C3% BFb%C3%9A1 %C2%BBl%C2 %95%2BS%C3 %8C%40zf%C 2%B0%C2%9B Z%1Fp%C2%8 8">
<input type="hidden" name="lc_x_os_timeunits" value="2">
<input type="hidden" name="ld1_x_os_timeunits" value="1">
<input type="hidden" name="ld2_x_os_timeunits" value="-1">
</span><input type="button" value="Calculate" onclick="calculate(this.fo rm);"></td >
</tr>
</table>
<p>
<input type="submit" name="btnAction" id="btnAction" value="ADD">
</form>
<form name="foccasion_of_service
<p>
<input type="hidden" name="a_add" value="A">
<table class="ewTable">
<tr>
<td class="ewTableHeader"><spa
<td class="ewTableAltRow"><spa
<input type="text" name="x_os_date" id="x_os_date" size="12" value="">
<img src="images/ew_calendar.gi
<script type="text/javascript">
Calendar.setup(
{
inputField : "x_os_date", // ID of the input field
ifFormat : "%d/%m/%Y", // the date format
button : "cx_os_date" // ID of the button
}
);
</script>
</span></td>
</tr>
<tr>
<td class="ewTableHeader"><spa
<td class="ewTableAltRow"><spa
<select id='x_hp_id' name='x_hp_id'><option value=''>Please Select</option></select>
<input type="hidden" name="s_x_hp_id" value="B%1B%C3%99%2Fwo%C2%
<input type="hidden" name="lc_x_hp_id" value="3">
<input type="hidden" name="ld1_x_hp_id" value="1">
<input type="hidden" name="ld2_x_hp_id" value="2">
</span></td>
</tr>
<tr>
<td class="ewTableHeader"><spa
<td class="ewTableAltRow"><spa
<select id='x_venue_id' name='x_venue_id'><option value=''>Please Select</option></select>
<input type="hidden" name="s_x_venue_id" value="%C3%B0!33!%C2%88%C3
<input type="hidden" name="lc_x_venue_id" value="2">
<input type="hidden" name="ld1_x_venue_id" value="1">
<input type="hidden" name="ld2_x_venue_id" value="-1">
</span></td>
</tr>
<tr>
<td class="ewTableHeader"><spa
<td class="ewTableAltRow"><spa
<table class="aspmakerlist"><tr><
<input type="radio" name="x_client_status" checked value="1">
New</td><td>
<input type="radio" name="x_client_status" value="2">
FUP</td><td> </td><td
</span></td>
</tr>
<tr>
<td class="ewTableHeader"><spa
<td class="ewTableAltRow"><spa
<table class="aspmakerlist"><tr><
<input type="radio" name="x_os_clienttype" checked value="1">
Ind</td><td>
<input type="radio" name="x_os_clienttype" value="2">
Grp</td><td> </td><td
</span></td>
</tr>
<tr>
<td class="ewTableHeader"><spa
<td class="ewTableAltRow"><spa
<select id='x_client_id' name='x_client_id'><option
<input type="hidden" name="s_x_client_id" value="%C2%85%C3%8E%C2%93%
<input type="hidden" name="lc_x_client_id" value="3">
<input type="hidden" name="ld1_x_client_id" value="1">
<input type="hidden" name="ld2_x_client_id" value="2">
</span></td>
</tr>
<tr>
<td class="ewTableHeader"><spa
<td class="ewTableAltRow"><spa
<select id='x_grpclient_id' name='x_grpclient_id'><opt
<input type="hidden" name="s_x_grpclient_id" value="G%60%C2%AE*%C3%96%C
<input type="hidden" name="lc_x_grpclient_id" value="2">
<input type="hidden" name="ld1_x_grpclient_id" value="1">
<input type="hidden" name="ld2_x_grpclient_id" value="-1">
</span></td>
</tr>
<tr>
<td class="ewTableHeader"><spa
<td class="ewTableAltRow"><spa
<input type="text" name="x_os_starttime" id="x_os_starttime" size="12" value="">
</span></td>
</tr>
<tr>
<td class="ewTableHeader"><spa
<td class="ewTableAltRow"><spa
<input type="text" name="x_os_endtime" id="x_os_endtime" size="12" value="">
</span></td>
</tr>
<tr>
<td class="ewTableHeader"><spa
<td class="ewTableAltRow"><spa
<input type="text" name="x_os_totalunits" id="x_os_totalunits" size="5" value="0">
</span><input type="button" value="Calculate" onclick="calculate(this.fo
</tr>
<tr>
<td class="ewTableHeader"><spa
<td class="ewTableAltRow"><spa
<select id='x_os_timeunits' name='x_os_timeunits'><opt
<input type="hidden" name="s_x_os_timeunits" value="0t%C3%A048%0EM%1B%0
<input type="hidden" name="lc_x_os_timeunits" value="2">
<input type="hidden" name="ld1_x_os_timeunits" value="1">
<input type="hidden" name="ld2_x_os_timeunits" value="-1">
</span><input type="button" value="Calculate" onclick="calculate(this.fo
</tr>
</table>
<p>
<input type="submit" name="btnAction" id="btnAction" value="ADD">
</form>
This is because I used the value of the option. You have
<option value='1' selected>15</option>
Either change it to
<option value='15' selected>15</option>
or change my original code to
var timeunits = parseInt(frm.x_os_timeunit s.options[ frm.x_os_t imeunits.s electedInd ex].text);
var units = Math.floor(minutes / timeunits);
<option value='1' selected>15</option>
Either change it to
<option value='15' selected>15</option>
or change my original code to
var timeunits = parseInt(frm.x_os_timeunit
var units = Math.floor(minutes / timeunits);
ASKER
Fantastic !!!
I used:
var timeunits = parseInt(frm.x_os_timeunit s.options[ frm.x_os_t imeunits.s electedInd ex].text);
var units = Math.floor(minutes / timeunits);
I promised to double your points but I have just read that I can't award more than 500points. I this true? Do you know how if it is at all possible? I wont PAQ this question just yet in case it is possible.
Thanks again.
PS: I am going to post another question in a couple of hours asking how to round up the total time units.
I used:
var timeunits = parseInt(frm.x_os_timeunit
var units = Math.floor(minutes / timeunits);
I promised to double your points but I have just read that I can't award more than 500points. I this true? Do you know how if it is at all possible? I wont PAQ this question just yet in case it is possible.
Thanks again.
PS: I am going to post another question in a couple of hours asking how to round up the total time units.
No, you should not give more than 500 points. On this site, points are just an extra--it's helping people that counts :-D I won't be around in a couple of hours, but your problem is easily fixed
Round units down (current)
var units = Math.floor(minutes / parseInt(frm.x_os_timeunit s.value));
Rounds units up
var units = Math.ceil(minutes / parseInt(frm.x_os_timeunit s.value));
Round
var units = Math.round(minutes / parseInt(frm.x_os_timeunit s.value));
Round units down (current)
var units = Math.floor(minutes / parseInt(frm.x_os_timeunit
Rounds units up
var units = Math.ceil(minutes / parseInt(frm.x_os_timeunit
Round
var units = Math.round(minutes / parseInt(frm.x_os_timeunit
ASKER
You are an absolute gem!!!
Thanks for all your help. You are not only helping but you are teaching too.
bagni99 :)
Thanks for all your help. You are not only helping but you are teaching too.
bagni99 :)
ASKER
I think we are getting really close.
I have tried the code and there seems to be one little glich.
If I use the example START TIME 10: 00, END TIME 11:00. The value returned in the TOTAL UNITS field is 60 (which is the minutes) instead of 4 (the total time units). I have tried entering different times and the value is clearly the minutes calculated...which is great, but now I also need the minutes divided by the TIME UNIT. Do you know what we need to do????
bagni99