N
Nitin
Hi
I have created function to check date and time. at the time of
execution, if date is left empty the function returns the error
message but then the focus goes to next field. Next filed is for time
and there is also a check on that. If time is empty return error
message. Again the explorer returns error message and then shifts the
focus to date field, again error message and focus goes to time and
this story goes on and on, untill browser is killed. can somebody help
me in debuggin this script.
Thanks a lot
Nitin
<head>
</HEAD>
<body>
<script language=javascript>
function CheckDate(sDate) {
var dateArray = sDate.value.split("/");
if (!/^\d{2}\/\d{2}\/\d{2}$/.test(sDate.value)) {
alert("Please enter a date in this format: dd/mm/yy.");
sDate.focus();
return false;
}
if (sDate.value.length < 8 )
{
alert("Date in not valid format");
sDate.focus();
return false;
}
var now= new Date();
var longYear= now.getYear();
longYear= (longYear+"").substring(2,4);
if (dateArray[2] < longYear) {
alert("Year "+dateArray[2]+" is wrong.");
sDate.focus();
return false;
}
if (dateArray[1] > 12 || dateArray[1] < 1) {
alert("Month "+dateArray[1]+" is wrong.");
sDate.focus();
return false;
}
if (dateArray[1] == 1 || dateArray[1] == 3 || dateArray[1] == 5 ||
dateArray[1] == 9 || dateArray[1] == 11){
if (dateArray[0] > 30 || dateArray[0] < 1){
alert("Date "+dateArray[0]+" in Month of "+dateArray[1]+" is
wrong");
sDate.focus();
return (false);
}
}
if (dateArray[1] == 4 || dateArray[1] == 6 || dateArray[1] == 7 ||
dateArray[1] == 8||dateArray[1] == 10||dateArray[1] == 12){
if (dateArray[0] > 31 || dateArray[0] < 1) {
alert("Date "+dateArray[0]+" in Month of "+dateArray[1]+" is
wrong");
sDate.focus();
return (false);
}
}
if (dateArray[1] == 2 && dateArray[0] > 29 || dateArray[0] < 1) {
alert("Date "+dateArray[0]+" in Month of "+dateArray[1]+" is
wrong.");
sDate.focus();
return (false);
}
return (true);
}
function CheckTime(sTime){
if (!/^([01]?[0-9]|[2][0-3])([:][0-5][0-9])?$/.test(sTime.value))
{
alert("Please enter the Time in this format:\n\n
hh:mm.");
sTime.focus();
return (false);
}
var timeArray = sTime.value.split(":");
if (sTime.value.length < 5 )
{
alert("Time in not valid format");
sTime.focus();
return (false);
}
if (sTime[0] > 23) {
alert(" hrs is not possible in a day. Invalid time.");
sTime.focus();
return (false);
}
if (sTime[1] > 60) {
alert ("mins is not possible in an hour. Invalid time.");
sTime.focus();
return (false);
}
return (true);
}
</script><HR><FORM METHOD="POST"
ACTION="/sso/cgi-bin/g100/g100_input_form.cgi/confirm"
ENCTYPE="application/x-www-form-urlencoded" NAME="input">
<TABLE CELLSPACING="0" BORDER="0" CELLPADDING="5" WIDTH="100%"><TR
ALIGN="left"><TD>Requestor</TD> <TD>Nitin Thakur</TD></TR>
<TR ALIGN="left"><TD>Email</TD> <TD>[email protected]</TD></TR>
<TR ALIGN="left"><TD>Date (GMT) (dd/mm/yy)</TD> <TD><INPUT TYPE="text"
NAME="startdate" VALUE="" SIZE=8 MAXLENGTH=8 ONBLUR="return
CheckDate(this)"></TD></TR>
<TR ALIGN="left"><TD>Time (GMT) 24 hrs format (hh:mm)</TD> <TD><INPUT
TYPE="text" NAME="starttime" VALUE="" SIZE=5 MAXLENGHT="5"
ONBLUR="return CheckTime(this)"></TD></TR>
<BR>
<TABLE CELLSPACING="0" BORDER="0" CELLPADDING="5" WIDTH="50%"><TR
ALIGN="center"><TD>
<INPUT TYPE="submit" NAME="confirm" VALUE="Submit"
</FORM></BODY></HTML>
I have created function to check date and time. at the time of
execution, if date is left empty the function returns the error
message but then the focus goes to next field. Next filed is for time
and there is also a check on that. If time is empty return error
message. Again the explorer returns error message and then shifts the
focus to date field, again error message and focus goes to time and
this story goes on and on, untill browser is killed. can somebody help
me in debuggin this script.
Thanks a lot
Nitin
<head>
</HEAD>
<body>
<script language=javascript>
function CheckDate(sDate) {
var dateArray = sDate.value.split("/");
if (!/^\d{2}\/\d{2}\/\d{2}$/.test(sDate.value)) {
alert("Please enter a date in this format: dd/mm/yy.");
sDate.focus();
return false;
}
if (sDate.value.length < 8 )
{
alert("Date in not valid format");
sDate.focus();
return false;
}
var now= new Date();
var longYear= now.getYear();
longYear= (longYear+"").substring(2,4);
if (dateArray[2] < longYear) {
alert("Year "+dateArray[2]+" is wrong.");
sDate.focus();
return false;
}
if (dateArray[1] > 12 || dateArray[1] < 1) {
alert("Month "+dateArray[1]+" is wrong.");
sDate.focus();
return false;
}
if (dateArray[1] == 1 || dateArray[1] == 3 || dateArray[1] == 5 ||
dateArray[1] == 9 || dateArray[1] == 11){
if (dateArray[0] > 30 || dateArray[0] < 1){
alert("Date "+dateArray[0]+" in Month of "+dateArray[1]+" is
wrong");
sDate.focus();
return (false);
}
}
if (dateArray[1] == 4 || dateArray[1] == 6 || dateArray[1] == 7 ||
dateArray[1] == 8||dateArray[1] == 10||dateArray[1] == 12){
if (dateArray[0] > 31 || dateArray[0] < 1) {
alert("Date "+dateArray[0]+" in Month of "+dateArray[1]+" is
wrong");
sDate.focus();
return (false);
}
}
if (dateArray[1] == 2 && dateArray[0] > 29 || dateArray[0] < 1) {
alert("Date "+dateArray[0]+" in Month of "+dateArray[1]+" is
wrong.");
sDate.focus();
return (false);
}
return (true);
}
function CheckTime(sTime){
if (!/^([01]?[0-9]|[2][0-3])([:][0-5][0-9])?$/.test(sTime.value))
{
alert("Please enter the Time in this format:\n\n
hh:mm.");
sTime.focus();
return (false);
}
var timeArray = sTime.value.split(":");
if (sTime.value.length < 5 )
{
alert("Time in not valid format");
sTime.focus();
return (false);
}
if (sTime[0] > 23) {
alert(" hrs is not possible in a day. Invalid time.");
sTime.focus();
return (false);
}
if (sTime[1] > 60) {
alert ("mins is not possible in an hour. Invalid time.");
sTime.focus();
return (false);
}
return (true);
}
</script><HR><FORM METHOD="POST"
ACTION="/sso/cgi-bin/g100/g100_input_form.cgi/confirm"
ENCTYPE="application/x-www-form-urlencoded" NAME="input">
<TABLE CELLSPACING="0" BORDER="0" CELLPADDING="5" WIDTH="100%"><TR
ALIGN="left"><TD>Requestor</TD> <TD>Nitin Thakur</TD></TR>
<TR ALIGN="left"><TD>Email</TD> <TD>[email protected]</TD></TR>
<TR ALIGN="left"><TD>Date (GMT) (dd/mm/yy)</TD> <TD><INPUT TYPE="text"
NAME="startdate" VALUE="" SIZE=8 MAXLENGTH=8 ONBLUR="return
CheckDate(this)"></TD></TR>
<TR ALIGN="left"><TD>Time (GMT) 24 hrs format (hh:mm)</TD> <TD><INPUT
TYPE="text" NAME="starttime" VALUE="" SIZE=5 MAXLENGHT="5"
ONBLUR="return CheckTime(this)"></TD></TR>
<BR>
<TABLE CELLSPACING="0" BORDER="0" CELLPADDING="5" WIDTH="50%"><TR
ALIGN="center"><TD>
<INPUT TYPE="submit" NAME="confirm" VALUE="Submit"
</FORM></BODY></HTML>