Click to See Complete Forum and Search --> : Date/time format


Squall Leonhart
11-20-2003, 06:38 PM
Hi, Guys.
I have question about date/time validation.
Please take a look at following code.

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript1.2" SRC="HM_Loader.js" TYPE='text/javascript'></SCRIPT>
<script language="JavaScript" type="text/javascript">

function checkthis()
{
if (document.frmAdd.description.value=="")
{
alert ('Please fill out textbox')
return false;
} else
{
if(confirm("Are you sure you want to add this?"))
{
return true;
}
else
{
return false;
}
}
}
</script>
</HEAD>
<BODY LEFTMARGIN=0 MARGINWIDTH="0" MARGINHEIGHT="0">
<%


Dim adoCon 'Holds the Database Connection Object
Dim rsEdit 'Holds the recordset for the new record to be added to the database
Dim strSQL 'Holds the SQL query for the database
Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("tech_re.mdb")
Set rsEdit = Server.CreateObject("ADODB.Recordset")
%>
<form name="frmAdd" method="post" action="updateRequest.asp?state=add" onsubmit="return checkthis();">
<table border="0" cellpadding="3" cellspacing="1" width="100%" class="forumline">
<tr>
<th class="thHead" colspan="2" height="25"><b>Add the new item</b></th>
</tr>
<tr>
<td class="row1" width="22%"><span class="gen"><b>Description</b></span></td>
<td class="row2" width="78%"><span class="gen"><input type="text" name="description" style="width:450px" maxlength="50"></span></td>
</tr>
<tr>
<td class="row1" width="22%"><span class="gen"><b>Date :</b></span></td>
<td class="row2" width="78%"><span class="gen"><%todaysDate=now()%><input type="text" name="Date" style="width:450px" maxlength="21" value="<%=FormatDateTime(todaysDate,0)%>"></span></td>
</tr>
<tr>
<td class="row1" width="22%"><span class="gen"><b>Status :</b></span></td>
<td class="row2" width="78%"> <span class="gen"><input type="checkbox" name="status"></span></td>
</tr>
<tr>
<td class="catBottom" colspan="2" align="center" height="28"><input type="submit" name="Submit" value="Submit">&nbsp&nbsp<button onClick="history.go(-1)" style="width:60px;">Go back</button></td>
</tr>
</table>
</form>
<%
'Reset server objects
rsEdit.Close
Set rsEdit = Nothing
Set adoCon = Nothing
%>
</BODY>
</HTML>


As you can see there is textbox named 'Date' on this page.
When this page appears, value <%=FormatDateTime(todaysDate,0)%> is inside textbox.
Problem is when user enters the time not as same format as one that appeared at first place.
How can I alert user "You haven't entered right format of date"?
Thanks. Please help me.:)

slyfox
11-21-2003, 05:50 AM
this one can get tricky... never the less.. what you ahve to do is have an onBlur="checkthis()" that validates your date fields.. if value is more than 12 in the "month" field then alert.. but then again if the date should be the 7th day of the 3rd month then your validator won't pick it up...

Solution:
All you do is create a drop down box for each, for day and month so the uder can select the date.

Khalid Ali
11-21-2003, 06:35 AM
There could be more then one approaches.
You can validate the input using

javascript for correct format,if you had

show the format you were talking about

,eiother I or some one else around

here will help you validate that

Squall Leonhart
11-21-2003, 11:53 AM
Format should be like this.
<%= FormatDateTime(todaysDate,0) %>

11/21/2003 12:48:04 PM

Squall Leonhart
11-21-2003, 03:55 PM
Help me please guys~:(

Squall Leonhart
11-21-2003, 06:20 PM
:) Please~

Squall Leonhart
11-24-2003, 10:49 AM
Help me guys~:)

Squall Leonhart
11-24-2003, 06:26 PM
:) Any solution?