No, I'm sure your explanation is clearer than I seem to testify; I often have difficulty communicating with people who have different thought-patterns than my own.
Now that I understand it's just an issue of multiples, try this... (Because the zero-padding for AsString was getting too complex for ternary statements, I put it all in a nested function. It uses logarithms to find the higher of the two powers of 10 closest to a number, then pads the number based on an argument and that power of 10.)
Code:
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Dividing The Hour</title>
<script type="text/javascript">
//Code provided by Dynamic Drive (http://www.dynamicdrive.com/forums/.
<!--
function Time(h, m, s) {
this.hours = typeof h == "number" ? h : 0;
this.minutes = typeof m == "number" ? m : 0;
this.seconds = typeof s == "number" ? s : 0;
}
Time.prototype.AddTime = function(time) {
this.AddHours(time.hours);
this.AddMinutes(time.minutes);
this.AddSeconds(time.seconds);
}
Time.prototype.AddHours = function(h) {
this.hours = (this.hours + h) % 576;
}
Time.prototype.AddMinutes = function(m) {
this.minutes += m;
this.AddMinutes(Math.floor(this.minutes / 60));
this.minutes %= 60;
}
Time.prototype.AddSeconds = function(s) {
this.seconds += s;
this.AddSeconds(Math.floor(this.seconds / 60));
this.seconds %= 60;
}
Time.prototype.AsString = function() {
var retval = '';
function padNum(num, digits){
var zeroes = digits - Math.ceil(Math.log(num) / Math.log(10));
for(var i = 0; i < zeroes; i++){
num = '0' + num;
}
return num;
}
return padNum(this.hours, 3) + ":" + padNum(this.minutes, 2) + ":" + padNum(this.seconds, 2);
}
// Output to text field...
function makeList(df) {
var hrnum = parseInt(df.hrnum.value) + 1;
var minnum = df.minnum.selectedIndex + 1;
var time = new Time(eval(df.hrnum.value), eval(df.minnum.selectedIndex), eval(df.secnum.value));
time.AddHours(0);
var Hour2401 = df.Hour2401.value;
df.Hour2401.value = time.AsString();
time.AddHours(1);
var Hour0102 = df.Hour0102.value;
df.Hour0102.value = time.AsString();
time.AddHours(1);
}
// -->
</script>
</head>
<body text="#000000" bgcolor="#FFFFD5" link="#0000EE" vlink="#551A8B" alink="#FF0000">
<center><table BORDER=0 CELLSPACING=2 CELLPADDING=5 COLS=1 WIDTH="600" >
<tr>
<td ALIGN=CENTER VALIGN=TOP WIDTH="50%"><form>
<center><table BORDER=0 CELLSPACING=0 CELLPADDING=5 COLS=4 WIDTH="320" >
<tr>
<td ALIGN=CENTER VALIGN=TOP WIDTH="60"><input type="text" name="hrnum" size="3"></td>
<td ALIGN=CENTER VALIGN=TOP WIDTH="60"><select name="minnum" size="1"><option>00</option><option>01</option><option>02</option><option>03</option><option>04</option><option>05</option><option>06</option><option>07</option><option>08</option><option>09</option><option>10</option><option>11</option><option>12</option><option>13</option><option>14</option><option>15</option><option>16</option><option>17</option><option>18</option><option>19</option><option>20</option><option>21</option><option>22</option><option>23</option><option>24</option><option>25</option><option>26</option><option>27</option><option>28</option><option>29</option><option>30</option><option>31</option><option>32</option><option>33</option><option>34</option><option>35</option><option>36</option><option>37</option><option>38</option><option>39</option><option>40</option><option>41</option><option>42</option><option>43</option><option>44</option><option>45</option><option>46</option><option>47</option><option>48</option><option>49</option><option>50</option><option>51</option><option>52</option><option>53</option><option>54</option><option>55</option><option>56</option><option>57</option><option>58</option><option>59</option></select></td>
<td><input type="text" name="secnum" value="30" size="2"></td>
<td ALIGN=CENTER VALIGN=TOP WIDTH="200"><input type="button" value="Hourly Module" onclick="makeList(this.form)" /></td>
</tr>
<tr>
<td>
<div align=right><b><font face="Tahoma"><font size=-1><font color="#3333FF">HH</font><font color="#FFFFD5">----</font><font color="#3333FF">:</font></font></font></b></div>
</td>
<td><b><font face="Tahoma"><font size=-1><font color="#FFFFD5">--</font><font color="#3333FF">MM</font></font></font></b></td>
<td></td>
</tr>
</table></center>
</td>
</tr>
<tr>
<td>
<center><input type="text" name="Hour2401" size="10">'24/1' Begins | <input type="text" name="Hour0102" size="10">'1/2'
Starts</form></center>
</td>
</tr>
</table></center>
</body>
</html>
Bookmarks