JRS: In article <11********************@z14g2000cwz.googlegroups.c om>,
dated Mon, 24 Jan 2005 05:27:01, seen in news:comp.lang.javascript,
pe*****@yahoo.com posted :
I have an asp page that uses a calendar.js (pop-up) file to add an
exact date format in the text field (txtDDate). My problem is I need
some javascript that sets an alert that does not allow them to select
today.
example:
var dtToday = Date()
Should be new Date() ; or at least that usually would be used.
In my browser, Date() gives a string unequal to that given by using
new Date().toString() . Date() ignores its parameter.
Both of them give date-and-time.
if(document.frmSoftware.txtDDate.value == dtToday)
The left side is a string as entered by the user, who *may* have used
the format that you expect.
{
alert("You cannot select same day distributions. Please enter a new
value in the \"Delivery Date\" field.");
Code should be indented to show intended structure.
In News, code lines should NOT be broken by the sending agent;
transmitted code should be executable directly. Better for you to do it
right than to have all your readers trying to repair the damage.
return false
}
But dtToday is blank....How can I get dtToday value?
Perhaps your system interprets Date() differently.
Also, when I set
the dtToday value outside javascript and used a Response.Write to see
what format Date() came up with - it gave me 1/24/2005 - but the
calendar pop-up gives me 01/24/2005....could this also be the issue?
Even though those are FFF, that is not the main issue; merely a residual
future cause of failure.
ISTM that you are asking to ensure that the requested date is not today.
But why? Very probably you want it to be after today, so disallowing
today-or-before.
If you check that the requested date is a valid date, preferably as
YYYY-MM-DD but in FFF if you must, then you can read it into a Date
Object and it will mean 00:00:00 local of the date in question. If it
were any earlier than 00:00:00 tomorrow, it would be 00:00:00 today or
earlier, i.e. before the current moment. You can therefore compare
new Date().valueOf() < new Date(userdata).valueOf()
if you are confident that the user format (after validation) is read
correctly in whatever localisation your system has; or
new Date().valueOf() < new Date(Y, M, D).valueOf()
with Y M D (or +Y +M +D) being generated during validation.
To check that a date is equal to another date, you must remove the time
components. Those blessed enough to be using GMT can use
(new Date()/864e5)|0 == (new Date(Y, M, D)/864e5)|0
but others will need to extract Y M D from each and use either
Y1==Y2 && M1==M2 && D1==D2
or as
(Y1*100+M1)*100+D1 == (Y2*100+M2)*100+D2
Read the newsgroup FAQ; see below.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.