Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 1st, 2003, 07:58 PM
Authorized User
Points: 447, Level: 7
Points: 447, Level: 7 Points: 447, Level: 7 Points: 447, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Adrian, MI, USA.
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Default validate date javascript

I'm very frustrated trying to accomplish a date validation using javascript. I currently am using the following which does not work.
Would someone be so kind as to tackle this for me? Much appreciated.



function ValiDate(oTextBox)
{
if(oTextBox.value < 8/25/2003 || oTextBox.value > 10/25/2003)
{
alert("Both 'Assigned Date' and 'Due Date' must range between 8/25/2003 and 10/25/2003");
return false;
}
else
return true;
}


.....
<input name="dtAsignedDate" type="text" id="dtAsignedDate" size="10" maxlength="10" value='10/1/2003' onChange="return ValiDate(document.frmAssign.dtAsignedDate)">


Reply With Quote
  #2 (permalink)  
Old October 2nd, 2003, 04:39 AM
Authorized User
 
Join Date: Jul 2003
Location: Athens, , Greece.
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, you 're not exactly in the right forum but.. check the code below. In order to compare the value of the text box with a Date, you must define it as a Date object (var now=new Date();).. and thats it!!
The example is working just fine

Cheers
Kostas Lagos
Code:
<script language="Javascript">
function ValiDate(oTextBox)
{
var now=new Date();
var ever=new Date();
now="08/25/2003";
ever="10/25/2003";
if(oTextBox.value < now | oTextBox.value > ever)    
{
alert("Both 'Assigned Date' and 'Due Date' must range between 8/25/2003 and 10/25/2003");
return false;
}
else    {
alert(oTextBox.value);
return true;
    }
}
</script>
</head>
<body>
<form name="frmAssign" method="post">
<input name="dtAsignedDate" type="text" id="dtAsignedDate" size="10" maxlength="10" value='10/1/2003' onChange="return ValiDate(document.frmAssign.dtAsignedDate);">
<input name="dtAsigned" type="text" id="dtAsigned" size="10" maxlength="10" value='10/1/2003'>
</form>

Reply With Quote
  #3 (permalink)  
Old October 2nd, 2003, 08:26 AM
Authorized User
Points: 447, Level: 7
Points: 447, Level: 7 Points: 447, Level: 7 Points: 447, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Adrian, MI, USA.
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry kosla78,
But when I tried your script, it always returned false, no matter if the date entered was within the acceptable range or not. So I tried to enhance it a little with the following but it doesn't work either. Boy this doesn't seem like rocket science but I can't find this anywhere on the web, surly someones done clientside date validation before. Thanks for your response.

function ValiDate(oTextBox)
{
var qtrstart =new Date();
var qtrend=new Date();
var entered=new Date();
qtrstart="8/25/2003";
qtrend="10/25/2003";
entered=oTextBox.value;
if(entered < qtrstart | entered > qtrend)
{
alert("Both 'Assigned Date' and 'Due Date' must range between 8/25/2003 and 10/25/2003");
return false;
}
else
return true;
}
Reply With Quote
  #4 (permalink)  
Old October 3rd, 2003, 04:07 PM
Authorized User
Points: 447, Level: 7
Points: 447, Level: 7 Points: 447, Level: 7 Points: 447, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Adrian, MI, USA.
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I know, no one in this forum cares, but just in case you use this area as a general purpose forum, here ya go, works like a champ.

function ValiDate(oTextBox)
{
//the values of these two strings are populated via an asp
//script that pulls start date and end date from my db table
var sd="8/25/2003"
var ed="10/25/2003"

//s,e and i are arrays ([2]=yyyy,[0]=mm,[1]=dd)
//s being the start date array
//e being the end date array
//i being the user input array
var s=sd.split('/')
var e=ed.split('/')
var i=oTextBox.value.split('/')

//create new date objects using constructed arrays
var startdate =new Date(s[2],s[0],s[1]);
var enddate=new Date(e[2],e[0],e[1]);
var inputdate=new Date(i[2],i[0],i[1]);

//run the comparison
if(inputdate.getTime() < startdate.getTime() || inputdate.getTime() > enddate.getTime())
{
alert("Both 'Assigned Date' and 'Due Date' must range between 8/25/2003 and 10/25/2003");
return false;
}
else
return true;
}
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Validate Radiobuttonlist using Javascript roseforever C# 1 November 6th, 2008 04:55 AM
Javascript to validate a textbox abhishekkashyap27 Javascript 9 May 6th, 2008 02:41 AM
How to validate date jijish ASP.NET 2.0 Professional 4 December 20th, 2007 07:17 AM
Validate Date sparc ASP.NET 1.0 and 1.1 Basics 1 September 20th, 2005 09:55 AM
Validate Expiration date mariakovacs Classic ASP Basics 4 January 26th, 2004 12:53 PM



All times are GMT -4. The time now is 06:06 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.