Hi All
I have a <SELECT> for the month (1 .. 12) and a <SELECT> for the year (2004
.... 2020), do you know of any js validation check I can use to check whether
these values are older than today's date so that I can bring up a warning,
eg
user chooses 04 and 2003 or 01 and 2004
OnClick a validate script sees that either of the above are older than
today's date and brings up an alert/doesn't submit the form.
Any ideas?
Rgds
Robbie
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
|
|
0
|
|
|
|
Reply
|
Astra
|
10/27/2004 11:03:12 AM |
|
Astra wrote:
> Hi All
>
> I have a <SELECT> for the month (1 .. 12) and a <SELECT> for the year (2004
> ... 2020), do you know of any js validation check I can use to check whether
> these values are older than today's date so that I can bring up a warning,
> eg
Do a search on "Re: Date format dd/mm" and a post by Mike Winter on
8 Oct. That, and Dr John Stockton's followup post, should answer any
question you may have regarding dates - oh, and look at the FAQ:
<URL:http://www.jibbering.com/faq/>
Dr. J also suggests looking at;
<URL:http://www.merlyn.demon.co.uk/js-index.htm>
Fred.
|
|
0
|
|
|
|
Reply
|
Fred
|
10/27/2004 12:02:56 PM
|
|
Thanks Fred
"Fred Oz" <ozfred@iinet.net.auau> wrote in message
news:417f8d4e$0$13744$5a62ac22@per-qv1-newsreader-01.iinet.net.au...
Astra wrote:
> Hi All
>
> I have a <SELECT> for the month (1 .. 12) and a <SELECT> for the year
> (2004
> ... 2020), do you know of any js validation check I can use to check
> whether
> these values are older than today's date so that I can bring up a warning,
> eg
Do a search on "Re: Date format dd/mm" and a post by Mike Winter on
8 Oct. That, and Dr John Stockton's followup post, should answer any
question you may have regarding dates - oh, and look at the FAQ:
<URL:http://www.jibbering.com/faq/>
Dr. J also suggests looking at;
<URL:http://www.merlyn.demon.co.uk/js-index.htm>
Fred.
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
|
|
0
|
|
|
|
Reply
|
Astra
|
10/27/2004 1:02:11 PM
|
|
On Wed, 27 Oct 2004 12:03:12 +0100, Astra <info@NoEmail.com> wrote:
> I have a <SELECT> for the month (1 .. 12) and a <SELECT> for the year
> (2004 ... 2020), do you know of any js validation check I can use to
> check whether these values are older than today's date so that I can
> bring up a warning,
You can create two Date objects. The first will have the current date,
whilst the second will be a copy modified to the selected month and year.
A simple comparison with then determine if the input is before the current
month.
/* This assumes that each OPTION element has a number with months
* being 1 to 12, and years being four digits.
*/
function isBeforeDate(form) {
/* The Date object uses zero-order month numbers, hence the -1. */
var month = +form.elements['monthSelect'].value - 1,
year = +form.elements['yearSelect'].value,
now = new Date(),
then = new Date(now);
then.setFullYear(year, month);
if(then < now) {
// The selected month/year is before the current month/year.
}
return (then < now);
}
<!-- Cancels the submission is the date is before this month. -->
<form ... onsubmit="return !isBeforeDate(this);">
Of course, you can integrate the validation into an existing submission
handler, but the check should only be done at this point. If you did it
when the SELECT elements are changed, you might catch the user in the
middle of changing the date to an acceptable date, doing nothing but
causing frustration.
[snip]
Hope that helps,
Mike
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
|
|
0
|
|
|
|
Reply
|
Michael
|
10/27/2004 1:03:26 PM
|
|
JRS: In article <417f7f77_4@127.0.0.1>, dated Wed, 27 Oct 2004
12:03:12, seen in news:comp.lang.javascript, Astra <info@NoEmail.com>
posted :
>I have a <SELECT> for the month (1 .. 12) and a <SELECT> for the year (2004
>... 2020), do you know of any js validation check I can use to check whether
>these values are older than today's date so that I can bring up a warning,
>eg
>
>user chooses 04 and 2003 or 01 and 2004
>
>OnClick a validate script sees that either of the above are older than
>today's date and brings up an alert/doesn't submit the form.
You may require to check more than one attempt during a given actual
month. You appear to guarantee field strings YYYY & MM. Therefore, it
is more effective to compare strings of the form YYYYMM.
with (new Date()) Now = String(getFullYear()*100 + getMonth() + 1)
if (YrField + MoField < Now) { ... // or <=
Creating unnecessary Date Objects wastes microseconds.
If getFullYear() is not with certainty available, as a short-term
solution you can use 2000 + getYear()%100 .
--
� 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.
|
|
0
|
|
|
|
Reply
|
Dr
|
10/27/2004 9:56:41 PM
|
|
On Wed, 27 Oct 2004 22:56:41 +0100, Dr John Stockton
<spam@merlyn.demon.co.uk> wrote:
[snip]
> You appear to guarantee field strings YYYY & MM. Therefore, it is more
> effective to compare strings of the form YYYYMM.
Indeed. I hadn't considered that (though it's quite an obvious solution).
[snip]
> Creating unnecessary Date Objects wastes microseconds.
Considering that the only reasonable time to perform this validation is at
form submission, even a delay of an entire second is meaningless.
> If getFullYear() is not with certainty available, [...]
This thought (or rather one concerning setFullYear) also crossed my mind,
so I decided to see when Netscape and Microsoft implemented setFullYear:
NN 4.06 and IE 4, respectively. I would assume that other browser vendors
implemented the method, and other similar ones, around that time.
Should the presence of set/getFullYear still remain a concern?
Mike
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
|
|
0
|
|
|
|
Reply
|
Michael
|
10/27/2004 11:30:36 PM
|
|
|
5 Replies
141 Views
(page loaded in 0.214 seconds)
|