By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,321 Members | 1,875 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,321 IT Pros & Developers. It's quick & easy.

get/format date field

P: n/a
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()
if(document.frmSoftware.txtDDate.value == dtToday)
{
alert("You cannot select same day distributions. Please enter a new
value in the \"Delivery Date\" field.");
return false
}

But dtToday is blank....How can I get dtToday value? 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?
Thanks is advance!
Lisa

Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
BMR
You should format dtToday with Date methods ie dtToday.toLocaleString()
or rather with getDate(), getMonth() and getFullYear(). Because when you
write dtToday, in fact it writes dtToday.toString(), which is "Mon Jan
24 17:06:17 2005" (my local time). dtToday is an object, not a variable.

BMR

pe*****@yahoo.com a écrit :
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()
if(document.frmSoftware.txtDDate.value == dtToday)
{
alert("You cannot select same day distributions. Please enter a new
value in the \"Delivery Date\" field.");
return false
}

But dtToday is blank....How can I get dtToday value? 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?
Thanks is advance!
Lisa

Jul 23 '05 #2

P: n/a
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.
Jul 23 '05 #3

P: n/a
John,
Thanks for the reply 'except for the indent comment' Not sure why you
would make that remark because you know google groups formats what you
paste to whatever it feels like.

In any case, I went another route and updated my calendar.js file to
not accept same day selection.

I will keep this chunk of info for future reference though
Thanks again

~L~

Jul 23 '05 #4

P: n/a
JRS: In article <11**********************@f14g2000cwb.googlegroups .com>
, dated Tue, 25 Jan 2005 10:50:53, seen in news:comp.lang.javascript,
peashoe <pe*****@yahoo.com> posted :
Thanks for the reply 'except for the indent comment' Not sure why you
would make that remark because you know google groups formats what you
paste to whatever it feels like.


You chose to use Google, when you could have chosen a proper newsreader
or a different, better-designed Web service. The responsibility is
yours; you do not yet live in a world-wide dictatorship forcing use of
Google.

Code should be indented to show the intended meaning; it is unreasonable
to expect others to fathom out the intended structure - which is not
necessarily the actual structure - of badly-presented material.

--
© 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.
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.