473,378 Members | 1,152 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Date Comparison- error in code posted

12
hi,
I am using the following javascript code to compare 2 dates, one of which is sysdate and the other is the date from my text field in my jsp.

function rbvalidation(ctl)
{
var cal = new Array();
cal.JAN = "January";
cal.FEB = "February";
cal.MAR = "March";
cal.APR = "April";
cal.MAY = "May";
cal.JUN = "June";
cal.JUL = "July";
cal.AUG = "August";
cal.SEP = "September";
cal.OCT = "October";
cal.NOV = "November";
cal.DEC = "December";

var sysDate = new Date();
var effDateChar = ctl.value; // P_EFFECTIVE_DATE

// translate date entered by user into JS format
var bufArray = effDateChar.split("-");
var effDateMonth = cal[bufArray[1].toUpperCase()];
var effDateDay = bufArray[0];
var effDateYear = bufArray[2];
var effDateDate = new Date(effDateMonth+" "+ effDateDay +
", "+effDateYear+" 23:59:59");

// compare the 2 dates
if (effDateDate < sysDate)
{
alert("The effective date must be today's date or a later date.");
ctl.focus();
return false;
}
return true;
}
</script>

Im calling this as onChange=rbvalidation(this.value) in my text field....
But, it is not working.Is something wrong with the code?
May 4 '07 #1
8 2033
acoder
16,027 Expert Mod 8TB
To use associative arrays, try:
Expand|Select|Wrap|Line Numbers
  1. cal['JAN']="January";
instead.
May 4 '07 #2
anju07
12
To use associative arrays, try:
Expand|Select|Wrap|Line Numbers
  1. cal['JAN']="January";
instead.
hi, i tried doing this, it yet does not work
May 5 '07 #3
acoder
16,027 Expert Mod 8TB
To set the date, create a new Date object and then use setFullYear.
May 5 '07 #4
pbmods
5,821 Expert 4TB
There's no such thing as an 'associative array' in JavaScript. You'd be better off just creating a generic object:

var cal = {
JAN: 'January',
FEB: 'February',
and so on....
};

When you declare var cal = new Array(), and then you set cal.JAN, you're not actually modifying the Array 'value' of the object. Instead, you're adding a new property.

This would do exactly the same thing:
var cal = new Date();
cal.JAN = 'January';

Or even:
var cal = Math;
cal.JAN = 'January';
May 5 '07 #5
anju07
12
There's no such thing as an 'associative array' in JavaScript. You'd be better off just creating a generic object:

var cal = {
JAN: 'January',
FEB: 'February',
and so on....
};

When you declare var cal = new Array(), and then you set cal.JAN, you're not actually modifying the Array 'value' of the object. Instead, you're adding a new property.

This would do exactly the same thing:
var cal = new Date();
cal.JAN = 'January';

Or even:
var cal = Math;
cal.JAN = 'January';

I applied the above logic, but it yet does not validate the field
May 7 '07 #6
pbmods
5,821 Expert 4TB
Depending on the format of the date, you could use Date.parse().

Expand|Select|Wrap|Line Numbers
  1. if(Date.parse(ctl.value) < new Date()) {
  2. ...
  3.  
Date.parse() is a little finicky, though, so you might want to use a calendar control .
May 7 '07 #7
acoder
16,027 Expert Mod 8TB
There's no such thing as an 'associative array' in JavaScript.
True, but using it in that way does work. Whether it's a good idea/style is a different matter.
May 8 '07 #8
acoder
16,027 Expert Mod 8TB
I applied the above logic, but it yet does not validate the field
Have you used the setFullYear method? That should solve your problem. Currently, the method that you're using to define the date is not correct.

Have you considered using select dropdowns instead? It will be much easier to validate. With a text box, the user could enter anything.
May 8 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Daniel Fisher | last post by:
Hi All! I'm fairly new to PhP and basicly trying to learn right now. Now I have a problem - I have a fairly large collection of movies which people keep borrowing from me. And then not returning....
16
by: Donnal Walter | last post by:
I was very surprised to discover that >>> import datetime >>> x = datetime.date(2004, 9, 14) >>> y = datetime.datetime(2004, 9, 14, 6, 43, 15) >>> print x == y True How can these two...
8
by: Lloyd Sheen | last post by:
Below is the output from command window. This shows values of variables and result of comparison. Make no sense except to dot.net. Any ideas?? ?pofile #11/11/2003 12:39:22 PM# ?pdtdbdate
1
by: colinhumber | last post by:
I have a datetime variable coming from my ASP.NET application that has a time portion. I give my users the option to perform an equals, greater than, less than, or between comparison. The trouble...
1
by: sylvian stone | last post by:
Hi, I've used standard date functions in the past, but need to create something a little different, as I am working on an investment calculator. What I need to do is validate two dates, and...
3
by: Karl Gibbon | last post by:
Hi There, I currently have a database in Access 2002 with several forms. I would like to restrict access to one form in perticular until November 1st every year. My current method (attempted...
6
by: MarkAurit | last post by:
Im having difficulty coming up with a good algorithm to express the following comparison: "if <a given date> falls between the (current date - 5 days) and the (current date)" Obviously....
3
by: Tiya | last post by:
Hi there !!! I would like to know how to compare dates in javascript. var sdate = new Date(theform.SubmissionDate.value); var odate = new Date(theform.StartDate.value); var todaysdate = new...
7
by: mr.nimz | last post by:
hello, this is antenio. recently i've come to a problem. i got a way through it, somehow, still it left me in a curious state, so i'm posting it here, if i can get an answer from some techy, ...
3
by: noone | last post by:
Hi, I am designing an application which displays news topics until midnight on the DisplayUntil date and then they should drop out. Unfortunately, they seem to be dropping out at mid-day. I'm...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.