PDA

View Full Version : Date/time format


Squall Leonhart
11-21-2003, 12:41 AM
Hi, Guys.
I have question about date/time validation.
Please take a look at following code.


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"> <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.

Kylena
11-21-2003, 08:20 AM
Why not call out a calendar to force users to select the date? The the field can be set to readonly.

I like to do this because then I only have to check the empty fields. :D

Code for the calendar can be found at Dynamic Drive (http://www.dynamicdrive.com)

Squall Leonhart
11-21-2003, 05:38 PM
how can I call out the calendar?

Squall Leonhart
11-21-2003, 09:57 PM
Please help me guys~:) :(

Roy Sinclair
11-21-2003, 10:07 PM
Check out http://www.codingforums.com/showthread.php?s=&threadid=12015&highlight=calendar

Squall Leonhart
11-22-2003, 12:17 AM
Can I just do alert box instead of calendar?
For example, if format is not 11/21/2003 12:48:04 PM ,
then alert user "Enter right format " something like that,.

Roy Sinclair
11-24-2003, 04:08 PM
Originally posted by Squall Leonhart
Can I just do alert box instead of calendar?
For example, if format is not 11/21/2003 12:48:04 PM ,
then alert user "Enter right format " something like that,.

Of course you can do that, but why make it difficult for the users?

Squall Leonhart
11-24-2003, 07:25 PM
Because calling calendar is hard for me to code.
:p Above calling callendar example is hard for me to understand because there is no code for that.:confused:

adios
11-24-2003, 07:57 PM
This (http://www.softcomplex.com/products/tigra_calendar/) works good.

Squall Leonhart
11-24-2003, 11:19 PM
Can I just do alert box instead of calendar?
Because the calendar is not necessary for me.
Since the format should be 11/21/2003 12:48:04 PM
For example, if format is not 11/21/2003 12:48:04 PM ,
then alert user "Enter right format " something like that,.

Squall Leonhart
11-25-2003, 09:41 PM
Please help me~:confused:

Roy Sinclair
12-02-2003, 04:40 PM
Originally posted by Squall Leonhart
Please help me~:confused:

Re-read my last reply, in the context of the message to which I replied.