Allows for the conversion back and forth from hours, minutes, and seconds to fractional hours. Input validation also ensures the time input does not contain invalid characters. Definitely a time-saver for time-related record keeping.
Add the below code to the <body> section of your page:
<scriptlanguage="javascript"type="text/javascript"> /* Visit http://www.yaldex.com/
for full source code
and get more free JavaScript, CSS and DHTML scripts! */
<!-- Begin function
checkInt(str){ if(!str)return0; var
ok =""; for(var
i =0;
i <
str.length;
i++){ varch=
str.substring(i,
i+1); if(ch<"0"||"9"<ch){ alert("Only
integer input is allowed!\n\n" +parseInt(ok)+" will be used because '" +
str +"' is invalid.\nYou may correct " +"this entry and try again."); returnparseInt(ok);
} else
ok +=ch;
} returnparseInt(str);
}
function
checkDecimal(str){ if(!str)return0; var
ok =""; for(var
i =0;
i <
str.length;
i++){ varch=
str.substring(i,
i+1); if((ch<"0"||"9"<ch)&&ch!='.'){ alert("Only
numeric input is allowed!\n\n" +parseFloat(ok)+" will be used because '" +
str +"' is invalid.\nYou may correct " +"this entry and try again."); returnparseFloat(ok);
} else
ok +=ch;
} return
str;
}
function
makeHours(form){ hour =(checkInt(form.hour.value));// validates input min=(checkInt(form.min.value));// sets invalid input to 0 sec =(checkInt(form.sec.value)); return(hour
+min/60+
sec/3600);
}
function
makeTime(form){ num =(checkDecimal(form.hourtotal.value));// validates input if(num){ form.hour.value=parseInt(num); num -=parseInt(num);
num *=60; form.min.value=parseInt(num); num -=parseInt(num);
num *=60; form.sec.value=parseInt(num); }
} // End --> </script> <formname="timeconverter"> <tableborder=1>
<tr>
<td>Time:</td>
<td> <inputtype=textname=hoursize=3maxlength=3>
Hours<br> <inputtype=textname=minsize=3maxlength=3>
Minutes<br> <inputtype=textname=secsize=3maxlength=3>
Seconds </td>
</tr>