Hello,
I'm having some serious problems debugging a script that I'm trying to make
work. I'm working on a form where a user can type in a time (in the format
of HH:MM), and another script automatically calculate how much time is
inbetween.
That part of it is working fine, but what ISN'T working fine is the script
that validates whether or not the user has entered the time in proper
syntax, and to make sure that the Time In does not come after the Time Out.
Here's the two functions, one to validate In and one to validate Out:
function validateInTimeF ormat(){
// This function validates whether or not a user has entered proper time
into the form
var inTime = document.frm.in Time.value;
if (validatingOutT ime == false) {
if (inTime.indexOf (":") == "-1"){
alert("Time In: You didn't put a \":\"");
this.document.f rm.inTime.focus ();
validatingInTim e = true;
return false;
} else if ((inTime.substr (0,inTime.index Of(":"))<1) ||
(inTime.substr( 0,inTime.indexO f(":"))>12)) {
alert("Please check to make sure your time is in the proper format
(hh/mm)");
document.frm.in Time.focus();
validatingInTim e = true;
return false;
} else if ((inTime.substr (inTime.indexOf (":")+1,inTime. length) < 0) ||
(inTime.substr( inTime.indexOf( ":")+1,inTime.l ength) > 59)) {
alert("Please check to make sure your time is in the proper format
(hh/mm)");
document.frm.in Time.focus();
validatingInTim e = true;
return false;
} else {
validatingInTim e = false;
return true;
}
}
}
function validateOutTime Format(){
// This function validates whether or not a user has entered proper time
into the form
var outTime = document.frm.ou tTime.value;
if (validatingInTi me == false) {
if (outTime.indexO f(":") == "-1"){
alert("Time In: You didn't put a \":\"");
this.document.f rm.outTime.focu s();
validatingOutTi me = true;
return false;
} else if ((outTime.subst r(0,outTime.ind exOf(":"))<1) ||
(outTime.substr (0,outTime.inde xOf(":"))>12)) {
alert("Please check to make sure your time is in the proper format
(hh/mm)");
document.frm.ou tTime.focus();
validatingOutTi me = true;
return false;
} else if ((outTime.subst r(outTime.index Of(":")+1,outTi me.length) < 0) ||
(outTime.substr (outTime.indexO f(":")+1,outTim e.length) > 59)) {
alert("Please check to make sure your time is in the proper format
(hh/mm)");
document.frm.ou tTime.focus();
validatingOutTi me = true;
return false;
} else {
validatingOutTi me = false;
return true;
}
}
}
Here's how i have it called in the page:
<br />Time: In <input name="inTime" type="text"
class="formInpu tText" id="inTime" size="5" onblur="return
validateInTimeF ormat();" />
<select name="inTime12H r" class="formInpu tText" id="inTime12Hr" >
<option value="AM">AM</option>
<option value="PM">PM</option>
</select><br />
Time: Out <input name="outTime" type="text" class="formInpu tText"
id="outTime" size="5" onblur="return validateOutTime Format();" />
<select name="outTime12 Hr" class="formInpu tText" id="outTime12Hr ">
<option value="AM">AM</option>
<option value="PM">PM</option>
</select>
FYI: I know I haven't done anything in the functions with the AM and PM.
Eventually I'll just have it add 12 hours to the result if it's PM, but I
haven't reached that point yet. I've been working in IE and also in Mozilla
Firefox (with the JavaScript Debugger). I get everything from "Error:
outTime has no properties" to some crazy nsexception type stuff in Mozilla.
I think the latter occurs when trying to focus the cursor back on the field
in question. It (somewhat) works in IE but not in Mozilla at all. Also,
noting the "if validatingInTim e==false" stuff, I had to do that because it
would automatically jump between the inTime field and outTiem field into
eternity if you clicked on one and then the other. Any clues on how much
I've screwed this up? JavaScript is SOOOOOOOOOOO difficult to debug.
Thanks in advance,
Kenneth
I'm having some serious problems debugging a script that I'm trying to make
work. I'm working on a form where a user can type in a time (in the format
of HH:MM), and another script automatically calculate how much time is
inbetween.
That part of it is working fine, but what ISN'T working fine is the script
that validates whether or not the user has entered the time in proper
syntax, and to make sure that the Time In does not come after the Time Out.
Here's the two functions, one to validate In and one to validate Out:
function validateInTimeF ormat(){
// This function validates whether or not a user has entered proper time
into the form
var inTime = document.frm.in Time.value;
if (validatingOutT ime == false) {
if (inTime.indexOf (":") == "-1"){
alert("Time In: You didn't put a \":\"");
this.document.f rm.inTime.focus ();
validatingInTim e = true;
return false;
} else if ((inTime.substr (0,inTime.index Of(":"))<1) ||
(inTime.substr( 0,inTime.indexO f(":"))>12)) {
alert("Please check to make sure your time is in the proper format
(hh/mm)");
document.frm.in Time.focus();
validatingInTim e = true;
return false;
} else if ((inTime.substr (inTime.indexOf (":")+1,inTime. length) < 0) ||
(inTime.substr( inTime.indexOf( ":")+1,inTime.l ength) > 59)) {
alert("Please check to make sure your time is in the proper format
(hh/mm)");
document.frm.in Time.focus();
validatingInTim e = true;
return false;
} else {
validatingInTim e = false;
return true;
}
}
}
function validateOutTime Format(){
// This function validates whether or not a user has entered proper time
into the form
var outTime = document.frm.ou tTime.value;
if (validatingInTi me == false) {
if (outTime.indexO f(":") == "-1"){
alert("Time In: You didn't put a \":\"");
this.document.f rm.outTime.focu s();
validatingOutTi me = true;
return false;
} else if ((outTime.subst r(0,outTime.ind exOf(":"))<1) ||
(outTime.substr (0,outTime.inde xOf(":"))>12)) {
alert("Please check to make sure your time is in the proper format
(hh/mm)");
document.frm.ou tTime.focus();
validatingOutTi me = true;
return false;
} else if ((outTime.subst r(outTime.index Of(":")+1,outTi me.length) < 0) ||
(outTime.substr (outTime.indexO f(":")+1,outTim e.length) > 59)) {
alert("Please check to make sure your time is in the proper format
(hh/mm)");
document.frm.ou tTime.focus();
validatingOutTi me = true;
return false;
} else {
validatingOutTi me = false;
return true;
}
}
}
Here's how i have it called in the page:
<br />Time: In <input name="inTime" type="text"
class="formInpu tText" id="inTime" size="5" onblur="return
validateInTimeF ormat();" />
<select name="inTime12H r" class="formInpu tText" id="inTime12Hr" >
<option value="AM">AM</option>
<option value="PM">PM</option>
</select><br />
Time: Out <input name="outTime" type="text" class="formInpu tText"
id="outTime" size="5" onblur="return validateOutTime Format();" />
<select name="outTime12 Hr" class="formInpu tText" id="outTime12Hr ">
<option value="AM">AM</option>
<option value="PM">PM</option>
</select>
FYI: I know I haven't done anything in the functions with the AM and PM.
Eventually I'll just have it add 12 hours to the result if it's PM, but I
haven't reached that point yet. I've been working in IE and also in Mozilla
Firefox (with the JavaScript Debugger). I get everything from "Error:
outTime has no properties" to some crazy nsexception type stuff in Mozilla.
I think the latter occurs when trying to focus the cursor back on the field
in question. It (somewhat) works in IE but not in Mozilla at all. Also,
noting the "if validatingInTim e==false" stuff, I had to do that because it
would automatically jump between the inTime field and outTiem field into
eternity if you clicked on one and then the other. Any clues on how much
I've screwed this up? JavaScript is SOOOOOOOOOOO difficult to debug.
Thanks in advance,
Kenneth
Comment