Entering a date into a form

B

Brian

I would like my users to enter a date into a text field
on my company Intranet. I know I could add three separate
drop downs for the month, day , and year. I would like to
force them to enter the date in one column and in the
format mm/dd/yyyy. Is there an easy way to do this or is
this a stupid noob question?

I am using FP 2002 & Access 2002 for the database. Would
using my SQL server be a better answer than using Access?

Thanks!

Brian
 
J

Jim Buyens

-----Original Message-----
I would like my users to enter a date into a text field
on my company Intranet. I know I could add three
separate drop downs for the month, day , and year. I
would like to force them to enter the date in one column
and in the format mm/dd/yyyy. Is there an easy way to do
this or is this a stupid noob question?

You would have to program that in JavaScript.
I am using FP 2002 & Access 2002 for the database. Would
using my SQL server be a better answer than using Access?

In general, yes, SQL Server is a better DBMS product than
Access. However, on publicly-hosted Web sites with low to
moderate volumes, Access is much easier to administer,
and usually cheaper.

Jim Buyens
Microsoft FrontPage MVP
http://www.interlacken.com
Author of:
*----------------------------------------------------
|\---------------------------------------------------
|| Microsoft Office FrontPage 2003 Inside Out
||---------------------------------------------------
|| Web Database Development Step by Step .NET Edition
|| Microsoft FrontPage Version 2002 Inside Out
|| Faster Smarter Beginning Programming
|| (All from Microsoft Press)
|/---------------------------------------------------
*----------------------------------------------------
 
B

Brian

I just bought Visual studio .Net. Could this also be done
ASP or one of the the other Visaul studio tools? If so,
could someone point me in the right direction?

Brian
 
T

Thomas A. Rowe

What date will the user be entering, today's date if they are completing the
form today, is so you can set the date to appear automatically with the form
submission by selecting the date option under form properties.

If you want use ASP, then you can not use the FP Form Handler. You would
have to custom write some ASP validation code.

--

==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
WEBMASTER Resources(tm)

FrontPage Resources, Forums, WebCircle,
MS KB Quick Links, etc.
==============================================
 
D

David Berry

You're still better off using JavaScript. For example:


//Check for Invalid Dates
function testKey(e){
chars= "0123456789/";
e = window.event;
if(chars.indexOf(String.fromCharCode(e.keyCode))==-1)
window.event.keyCode=0;
};

function valDate(M, D, Y){
Months= new Array(31,28,31,30,31,30,31,31,30,31,30,31);
Leap = false;

if((Y % 4 == 0) && ((Y % 100 != 0) || (Y %400 == 0)))
Leap = true;
if((D < 1) || (D > 31) || (M < 1) || (M > 12) || (Y < 0))
return(false);
if((D > Months[M-1]) && !((M == 2) && (D > 28)))
return(false);
if(!(Leap) && (M == 2) && (D > 28))
return(false);
if((Leap) && (M == 2) && (D > 29))
return(false);
};

function formatDate(dateForm){
cDate = dateForm.value;
dSize = cDate.length;
sCount= 0;

if(cDate=='') return;

//Check out the slashs
for(var i=0; i < dSize; i++)
(cDate.substr(i,1) == "/") ? sCount++ : sCount;
if (sCount != 2){
alert("The Date must be in the format\n ''DD/MM/YYYY''");
dateForm.select();
return(false);
};
//Check if the year is a 2 or 4 digits string
ySize = cDate.substring(cDate.lastIndexOf("/")+1,dSize).length
if(ySize<2 || ySize>4 || ySize == 3){
alert("You've entered an Invalid Date");
dateForm.select();
return false;
};
//Cut the date string into three parts (Month, Day & Year)
idxBarI = cDate.indexOf("/");
idxBarII= cDate.lastIndexOf("/");
strM = cDate.substring(0,idxBarI);
strD = cDate.substring(idxBarI+1,idxBarII);
strY = cDate.substring(idxBarII+1,dSize);

strM = (strM.length < 2 ? '0'+strM : strM);
strD = (strD.length < 2 ? '0'+strD : strD);
if(strY.length == 2)
strY = (strY > 50 ? '19'+strY : '20'+strY);
dateForm.value = strM+'/'+strD+'/'+strY;

ok = valDate(strM, strD, strY);
if(ok==false){
alert("You've entered an Invalid Date");
dateForm.select();
return false;
};
};


Then add it to your field like this:

<input type="text" name="Date" onBlur="formatDate(this)"
onKeyPress="testKey(event)" size="10">
 
J

Jim Buyens

Brian said:
I just bought Visual studio .Net. Could this also be done
ASP or one of the the other Visaul studio tools? If so,
could someone point me in the right direction?

If you're going to develop your application in ASP.NET, then
you can attach something called a "Regular Expression Validator"
to your text box, and specify any matching pattern you want.

Alternatively, you could validate the form with ASP.NET code that
runs on the Web server.

Jim Buyens
Microsoft FrontPage MVP
http://www.interlacken.com
Author of:
*----------------------------------------------------
|\---------------------------------------------------
|| Microsoft Office FrontPage 2003 Inside Out
||---------------------------------------------------
|| Web Database Development Step by Step .NET Edition
|| Microsoft FrontPage Version 2002 Inside Out
|| Faster Smarter Beginning Programming
|| (All from Microsoft Press)
|/---------------------------------------------------
*----------------------------------------------------
 
Top