[Javascript] RE: Checking for date

Senior, Henry (TWIi London) HSenior at twii.net
Tue Jul 30 12:23:45 CDT 2002


Andrew, 
	this is a fairly comprehensive script for checking dates. It trims
entries of whitespace, then checks the format for dd/mm/yyyy, checks to see
if day and months values are valid - ie it calculates leap year values for
Feb etc.
The instruction: <%=FormatDate("PL", Now())%> gets an ASP date and the
confirm() gives the user the options to revert to today's date - you may
have to change or remove this depending on what server environment you use.

The function works in IE,NS4,NS6.

To put it in a page use something like <input type="text"
onblur="val(this)">.

function getLeap(hmm){
	if((hmm%4==0)&&(hmm%100!=0||hmm%400==0)){
	return 29
	}
	else{
	return 28
	}
}

function val(elem){
txt = elem.value
txt = txt.replace(/^\s+/,"");
txt = txt.replace(/\s+$/,"");
elem.value = txt;
var rege = /\d\d\/\d\d\/\d\d\d\d/;

var brief = txt.match(rege)

	if(!brief){//if date is not of format dd/mm/yyyyy
	if(confirm('This is not a valid date, do you wish to\n revert to
today\'s date?'))
	{elem.value="<%=FormatDate("PL", Now())%>"}
	else
	{elem.value="";}
	return;}

var info = brief[0].match(/\d+/g)

var dateInfo = new Array()
dateInfo[1] = 31;
dateInfo[2] = getLeap(info[2]);
dateInfo[3] = 31;
dateInfo[4] = 30;
dateInfo[5] = 31;
dateInfo[6] = 30;
dateInfo[7] = 31;
dateInfo[8] = 31;
dateInfo[9] = 30;
dateInfo[10] = 31;
dateInfo[11] = 30;
dateInfo[12] = 31;

	if(info[1]>12){//if month is greater than 12
	if(confirm('This is not a valid month, do you wish to\n revert to
the default date?'))
	{elem.value="<%=FormatDate("PL", Now())%>"}
	else{elem.value="";}
	
	return;}
	
	if(info[0]>dateInfo[parseInt(info[1])]){//if day is not valid -
leapyears/feb taken into account
	alert('This is not a valid day');
	elem.value="";
	return;}
}

-----Original Message-----
From: javascript-request at LaTech.edu
[mailto:javascript-request at LaTech.edu]
Sent: 30 July 2002 18:01
To: javascript at LaTech.edu
Subject: Javascript digest, Vol 1 #710 - 11 msgs


Send Javascript mailing list submissions to
	javascript at LaTech.edu

To subscribe or unsubscribe via the World Wide Web, visit
	https://lists.LaTech.edu/mailman/listinfo/javascript
or, via email, send a message with subject or body 'help' to
	javascript-request at LaTech.edu

You can reach the person managing the list at
	javascript-admin at LaTech.edu

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Javascript digest..."


Today's Topics:

   1. Changing a Div's Style- margin-left in IE5.5 (none)
   2. RE: Changing a Div's Style- margin-left in IE5.5 (Peter Brunone)
   3. Open page in frame from popup window (Phillip Morgan)
   4. RE: Open page in frame from popup window (Peter Brunone)
   5. Re: Open page in frame from popup window (Rodney Myers)
   6. Checking for date (Andrew Gibson)
   7. RE: Checking for date (Alan Easton)
   8. Re: Checking for date (Dan Costea)
   9. RE: Open page in frame from popup window (Peter Brunone)
  10. RE: Changing a Div's Style- margin-left in IE5.5 (Cutter Bl)
  11. Re: Open page in frame from popup window (Rodney Myers)

--__--__--

Message: 1
From: "none" <extstarrfam at cox-internet.com>
To: <javascript at LaTech.edu>
Date: Mon, 29 Jul 2002 09:16:07 -0500
Subject: [Javascript] Changing a Div's Style- margin-left in IE5.5
Reply-To: javascript at LaTech.edu

What I want to do is move the div element which has the
image of a red ball in it.  I am trying to do so by
changing the style's margin-left value to 100 points.
I am using IE5.5.  Simply stated, I do not know how to
write the function moveBall.  Will someone please write
in the correct process for this funciton and give a few
comments to explain what they did.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">
<html><head><title>Move a Ball Once in IE</title>
<script type="text/javascript1.2">
<!--

function moveBall( ) {
 document.all['red'].style.margin-left="100pt";
}

//-->
</script>
</head>
<body>
<div id="red" style="height:40px; width:40px;
margin-left:10pt; margin-top:40pt">
<img src="Ball- red.jpg" height="40" width="40"
id="redball" name="redball">
</div>
<form>
<input type="button" value="Move Ball" name="move"
id="move" title="Move" onclick="moveBall( )">
</form>
</body>
</html>



--__--__--

Message: 2
From: "Peter Brunone" <peter at brunone.com>
To: <javascript at LaTech.edu>
Subject: RE: [Javascript] Changing a Div's Style- margin-left in IE5.5
Date: Mon, 29 Jul 2002 22:48:56 -0500
Organization: Your Name Here
Reply-To: javascript at LaTech.edu


	document.all.red.style.marginLeft="100pt";

	For what it's worth, "red" may be a bad name to give an element; I
know
it's recognized color in CSS and HTML.  I try to stay away from words that
mean anything when naming my objects... just my two cents, so use it as you
will.

Cheers,

Peter

|-----Original Message-----
|From: javascript-admin at LaTech.edu [mailto:javascript-admin at LaTech.edu]On
|Behalf Of none
|
|What I want to do is move the div element which has the
|image of a red ball in it.  I am trying to do so by
|changing the style's margin-left value to 100 points.
|I am using IE5.5.  Simply stated, I do not know how to
|write the function moveBall.  Will someone please write
|in the correct process for this funciton and give a few
|comments to explain what they did.
|
|<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
|Transitional//EN"
| "http://www.w3.org/TR/html4/loose.dtd">
|<html><head><title>Move a Ball Once in IE</title>
|<script type="text/javascript1.2">
|<!--
|
|function moveBall( ) {
| document.all['red'].style.margin-left="100pt";
|}
|
|//-->
|</script>
|</head>
|<body>
|<div id="red" style="height:40px; width:40px;
|margin-left:10pt; margin-top:40pt">
|<img src="Ball- red.jpg" height="40" width="40"
|id="redball" name="redball">
|</div>
|<form>
|<input type="button" value="Move Ball" name="move"
|id="move" title="Move" onclick="moveBall( )">
|</form>
|</body>
|</html>
|


--__--__--

Message: 3
Date: Tue, 30 Jul 2002 14:06:30 +1000
From: "Phillip Morgan" <pmorgan at qpbd999.quickpages.net.au>
To: javascript at LaTech.edu
Subject: [Javascript] Open page in frame from popup window
Reply-To: javascript at LaTech.edu

Hi All,

I have a site I'm putting together which is framed. It pops up a small 
navigation page with links to other pages. I'd like the links in this 
navigation page to open the selected page in the parent framed site.

There are 4 frames on the main page: topleft, navleft, navtop and 
mainFrame. The links in the popup nav window need to load the linked 
pages in mainFrame.

How can I do this?

tia
phill

-- 


--__--__--

Message: 4
From: "Peter Brunone" <peter at brunone.com>
To: <javascript at LaTech.edu>
Subject: RE: [Javascript] Open page in frame from popup window
Date: Mon, 29 Jul 2002 23:11:01 -0500
Organization: Your Name Here
Reply-To: javascript at LaTech.edu

Phill,

	First, make sure that when you open the window, you set it to a
variable,
and then assign the opener property in case it wasn't set, e.g.

var newWin = window.open(yadda yadda);
newWin.opener = top;

	And then in the new window:

window.opener.frames.mainFrame.location.href = "whatever.html";

Regards,

Peter

|-----Original Message-----
|From: javascript-admin at LaTech.edu [mailto:javascript-admin at LaTech.edu]On
|Behalf Of Phillip Morgan
|
|Hi All,
|
|I have a site I'm putting together which is framed. It pops up a small
|navigation page with links to other pages. I'd like the links in this
|navigation page to open the selected page in the parent framed site.
|
|There are 4 frames on the main page: topleft, navleft, navtop and
|mainFrame. The links in the popup nav window need to load the linked
|pages in mainFrame.
|
|How can I do this?
|
|tia
|phill
|


--__--__--

Message: 5
Date: Tue, 30 Jul 2002 10:08:21 +0100
From: Rodney Myers <rodney at aflyingstart.net>
To: javascript at LaTech.edu
Subject: Re: [Javascript] Open page in frame from popup window
Reply-To: javascript at LaTech.edu

Or just
window.opener.top.mainFrame.location.href = "whatever.html";
??

Rodney

Peter Brunone wrote:

> Phill,
>
>         First, make sure that when you open the window, you set it to a
variable,
> and then assign the opener property in case it wasn't set, e.g.
>
> var newWin = window.open(yadda yadda);
> newWin.opener = top;
>
>         And then in the new window:
>
> window.opener.frames.mainFrame.location.href = "whatever.html";
>
> Regards,
>
> Peter
>
> |-----Original Message-----
> |Behalf Of Phillip Morgan
> |I have a site I'm putting together which is framed. It pops up a small
> |navigation page with links to other pages. I'd like the links in this
> |navigation page to open the selected page in the parent framed site.
> |
> |There are 4 frames on the main page: topleft, navleft, navtop and
> |mainFrame. The links in the popup nav window need to load the linked
> |pages in mainFrame.
> |
> |How can I do this?



--__--__--

Message: 6
From: "Andrew Gibson" <andyg at ihug.co.nz>
To: <javascript at LaTech.edu>
Date: Wed, 31 Jul 2002 23:19:03 +1200
Subject: [Javascript] Checking for date
Reply-To: javascript at LaTech.edu

If a user types in a date on a form, like so

30,June 2002

How could I check in Javascript to ensure it is a valid date, and in the
format I want, say,    dd mmm,yyyy

Andrew Gibson



--__--__--

Message: 7
From: Alan Easton <alan.easton at unn.ac.uk>
To: "'javascript at LaTech.edu'" <javascript at LaTech.edu>
Subject: RE: [Javascript] Checking for date
Date: Tue, 30 Jul 2002 12:26:13 +0100
Reply-To: javascript at LaTech.edu

Check out http://javascript.internet.com/forms/ for some general date
validation scripts. You may be able to tailor them to your specific needs.

AE...

-----Original Message-----
From: Andrew Gibson [mailto:andyg at ihug.co.nz]
Sent: 31 July 2002 12:19
To: javascript
Subject: [Javascript] Checking for date


If a user types in a date on a form, like so

30,June 2002

How could I check in Javascript to ensure it is a valid date, and in the
format I want, say,    dd mmm,yyyy

Andrew Gibson


_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript

--__--__--

Message: 8
From: "Dan Costea" <costea.dan at ssi-schaefer.ro>
To: <javascript at LaTech.edu>
Subject: Re: [Javascript] Checking for date
Date: Tue, 30 Jul 2002 14:34:17 +0300
Reply-To: javascript at LaTech.edu

here is a useful date valiadation:
http://www.mattkruse.com/javascript/date/


----- Original Message ----- 
From: "Andrew Gibson" <andyg at ihug.co.nz>
To: <javascript at LaTech.edu>
Sent: Wednesday, July 31, 2002 2:19 PM
Subject: [Javascript] Checking for date


> If a user types in a date on a form, like so
> 
> 30,June 2002
> 
> How could I check in Javascript to ensure it is a valid date, and in the
> format I want, say,    dd mmm,yyyy
> 
> Andrew Gibson
> 
> 
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript


--__--__--

Message: 9
From: "Peter Brunone" <peter at brunone.com>
To: <javascript at LaTech.edu>
Subject: RE: [Javascript] Open page in frame from popup window
Date: Tue, 30 Jul 2002 07:24:07 -0500
Organization: Your Name Here
Reply-To: javascript at LaTech.edu


	Maybe it's just old-school precaution, but not every browser assigns
the
opener attribute implicitly.  I didn't know the target audience, and an
extra line or two of code won't make or break a site.

|-----Original Message-----
|From: javascript-admin at LaTech.edu [mailto:javascript-admin at LaTech.edu]On
|Behalf Of Rodney Myers
|
|Or just
|window.opener.top.mainFrame.location.href = "whatever.html";
|??
|
|Rodney
|
|Peter Brunone wrote:
|
|> Phill,
|>
|>         First, make sure that when you open the window, you set
|it to a variable,
|> and then assign the opener property in case it wasn't set, e.g.
|>
|> var newWin = window.open(yadda yadda);
|> newWin.opener = top;
|>
|>         And then in the new window:
|>
|> window.opener.frames.mainFrame.location.href = "whatever.html";
|>
|> Regards,
|>
|> Peter
|>
|> |-----Original Message-----
|> |Behalf Of Phillip Morgan
|> |I have a site I'm putting together which is framed. It pops up a small
|> |navigation page with links to other pages. I'd like the links in this
|> |navigation page to open the selected page in the parent framed site.
|> |
|> |There are 4 frames on the main page: topleft, navleft, navtop and
|> |mainFrame. The links in the popup nav window need to load the linked
|> |pages in mainFrame.
|> |
|> |How can I do this?
|
|
|_______________________________________________
|Javascript mailing list
|Javascript at LaTech.edu
|https://lists.LaTech.edu/mailman/listinfo/javascript
|


--__--__--

Message: 10
From: "Cutter Bl" <cutterbl at hotmail.com>
To: javascript at LaTech.edu
Subject: RE: [Javascript] Changing a Div's Style- margin-left in IE5.5
Date: Tue, 30 Jul 2002 08:21:11 -0400
Reply-To: javascript at LaTech.edu

I somewhat agree with Peter. Although I would not use "red" because it may 
be a recognized attribute, it's usually good programming practice to give 
your objects some form of recognizable name. Maybe something like 
'id="idMobileBox"'.

Cutter
Falcon Knives

----Original Message Follows----
From: "Peter Brunone" <peter at brunone.com>
Reply-To: javascript at LaTech.edu
To: <javascript at LaTech.edu>
Subject: RE: [Javascript] Changing a Div's Style- margin-left in IE5.5
Date: Mon, 29 Jul 2002 22:48:56 -0500


	document.all.red.style.marginLeft="100pt";

	For what it's worth, "red" may be a bad name to give an element; I
know
it's recognized color in CSS and HTML.  I try to stay away from words that
mean anything when naming my objects... just my two cents, so use it as you
will.

Cheers,

Peter

|-----Original Message-----
|From: javascript-admin at LaTech.edu [mailto:javascript-admin at LaTech.edu]On
|Behalf Of none
|
|What I want to do is move the div element which has the
|image of a red ball in it.  I am trying to do so by
|changing the style's margin-left value to 100 points.
|I am using IE5.5.  Simply stated, I do not know how to
|write the function moveBall.  Will someone please write
|in the correct process for this funciton and give a few
|comments to explain what they did.
|
|<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
|Transitional//EN"
| "http://www.w3.org/TR/html4/loose.dtd">
|<html><head><title>Move a Ball Once in IE</title>
|<script type="text/javascript1.2">
|<!--
|
|function moveBall( ) {
| document.all['red'].style.margin-left="100pt";
|}
|
|//-->
|</script>
|</head>
|<body>
|<div id="red" style="height:40px; width:40px;
|margin-left:10pt; margin-top:40pt">
|<img src="Ball- red.jpg" height="40" width="40"
|id="redball" name="redball">
|</div>
|<form>
|<input type="button" value="Move Ball" name="move"
|id="move" title="Move" onclick="moveBall( )">
|</form>
|</body>
|</html>
|

_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript


_________________________________________________________________
Join the world's largest e-mail service with MSN Hotmail. 
http://www.hotmail.com


--__--__--

Message: 11
Date: Tue, 30 Jul 2002 13:42:31 +0100
From: Rodney Myers <rodney at aflyingstart.net>
To: javascript at LaTech.edu
Subject: Re: [Javascript] Open page in frame from popup window
Reply-To: javascript at LaTech.edu

Thank you Peter,
I like to be 'old school'  too but sometimes one misses things like this.
Rodney.

Peter Brunone wrote:

>         Maybe it's just old-school precaution, but not every browser
assigns the
> opener attribute implicitly.  I didn't know the target audience, and an
> extra line or two of code won't make or break a site.
>
> |-----Original Message-----
> |Behalf Of Rodney Myers
> |
> |Or just
> |window.opener.top.mainFrame.location.href = "whatever.html";
> |??
> |
> |Rodney
> |




--__--__--

_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript


End of Javascript Digest


DISCLAIMER - The preceding e-mail message (including any attachments)
contains information that may be confidential, may be protected by the
attorney-client or other applicable privileges, or may constitute non-public
information.  It is intended to be conveyed only to the designated
recipient(s) named above.  If you are not an intended recipient of this
message, or have otherwise received it in error, please notify the sender by
replying to this message and then delete all copies of it from your computer
system.  Any use, dissemination, distribution, or reproduction of this
message by unintended recipients is not authorized and may be unlawful. The
contents of this communication do not necessarily represent the views of
this company.



More information about the Javascript mailing list