JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 27th, 2003, 09:32 AM
vous vous is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 14 vous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Date validation with JavaScript inside a CGI script....not working!!

Hello All, I'm trying to validate a date field on the client side with JavaScript inside a CGI script....

The JavaScript standalone works but when I put inside the CGI script it doesn't....would anybody be able to give me a hand?

Here is the code:


### BEGIN HTML

print "<html>";
print "<head>";
print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">";
print "<link rel=\"stylesheet\" href=\"/bugzilla/css/overzetten.css\">";




############## JavaScript Date Validation BEGIN ##############

print <<DateValJS;

<script type="text/javascript" language="JavaScript">

function checkdate(xxfield) {
if (!xxfield) return;
if (!xxfield.value || /^\s+$/.test(xxfield.value)) { //empty string/spaces
return true;
}
if (!/^\d{2}\/\d{2}\/\d{4}$/.test(xxfield.value)) { // mm/dd/yyyy format
alert('Please enter a date in this format:\n\n mm/dd/yyyy.');
xxfield.focus();
xxfield.select(); //optional
return false;
}
var strSeparator = '/';
var arrayDate = xxfield.value.split(strSeparator);
var arrayLookup = {'01':31,'03':31,'04':30,'05':31,'06':30,'07':31,'08':31,'09':30,'10':31,'11':30,'12':31};
var intDay = parseInt(arrayDate[1]);
if (arrayLookup[arrayDate[0]] != null) {
if (intDay <= arrayLookup[arrayDate[0]] && intDay != 0) //correct day for month
return true;
} else if (arrayDate[0] == '02') { //check Feb. leap/non-leap
var intYear = parseInt(arrayDate[2]);
if (((intYear % 4 == 0 && intDay <= 29) || (intYear % 4 != 0 && intDay <=28)) && intDay !=0)
return true;
}
alert('This is not a valid date.\n\nPlease re-enter in the format mm/dd/yyyy.');
xxfield.focus();
xxfield.select(); //optional
return false;
}

</script>

DateValJS

############## JavaScript Date Validation END ##############







print "</head>";

print "<body>";
print "<form method=\"post\" action=\"enter_overzetten.cgi\" enctype=\"multipart/formdata\" name=\"enter_overzetten\" >";
print "<table border=\"0\">";

print "<tr>";
print "<td valign=\"middle\" align=\"left\"><font face=\"Arial, Helvetica, sans-serif\" size=\"2\" color=\"#000000\">ontw_test_overzetdatum</font></th>";
print "<td valign=\"middle\" align=\"left\"><input type=text name=\"ontw_test_overzetdatum\" size=40 onclick=\"highlight(event)\"
onblur=\"return checkdate(this.form.ontw_test_overzetdatum)\"></th>"; <---THIS IS THE FIELD!!!
print "</tr>";

Reply With Quote
  #2  
Old August 27th, 2003, 09:41 AM
ishnid's Avatar
ishnid ishnid is offline
kill 9, $$;
Dev Shed God 4th Plane (6500 - 6999 posts)
 
Join Date: Sep 2001
Location: Shanghai, An tSín
Posts: 6,894 ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level) 
Time spent in forums: 4 Months 2 Weeks 1 Day 22 h 37 m 21 sec
Reputation Power: 3885
You'll have to be more specific than that. When it doesn't work, what does happen. What errors do you get?

Reply With Quote
  #3  
Old August 27th, 2003, 09:49 AM
vous vous is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 14 vous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
It is supposed to come up with a pop up window telling the user he has not entered the date correctly. This should happen after the user leaves the field.


What is happening is nothing, it does not come up with the pop-up, nor do I get error messages.

Last edited by vous : August 27th, 2003 at 09:52 AM.

Reply With Quote
  #4  
Old August 27th, 2003, 10:12 AM
ishnid's Avatar
ishnid ishnid is offline
kill 9, $$;
Dev Shed God 4th Plane (6500 - 6999 posts)
 
Join Date: Sep 2001
Location: Shanghai, An tSín
Posts: 6,894 ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level) 
Time spent in forums: 4 Months 2 Weeks 1 Day 22 h 37 m 21 sec
Reputation Power: 3885
Unfortunately, I don't know much about javascript so I may not be of much use. Have you checked the source of the page that's output to check if it was printed correctly and matches your standalone page?

Reply With Quote
  #5  
Old August 27th, 2003, 10:15 AM
vous vous is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 14 vous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Yup, that's the first thing I checked, but no luck, the output in HTML is OK....tanxs though!

Anybody, any thoughts?

Reply With Quote
  #6  
Old August 27th, 2003, 12:57 PM
Ctb's Avatar
Ctb Ctb is offline
An Ominous Coward
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: Jan 2002
Posts: 4,425 Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 3 Weeks 10 h
Reputation Power: 0
Look into using HTML::Template. Using templates will allow you to write regular old JavaScript into your HTML pages without jumping through a lot of hoops with escaping and print() statements and whatnot. It's sooooooo much easier to debug and edit your CGI-altered HTML pages that you'll wonder how you ever lived without it!

Reply With Quote
  #7  
Old August 27th, 2003, 02:46 PM
Hero Zzyzzx's Avatar
Hero Zzyzzx Hero Zzyzzx is offline
11
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Jul 2001
Location: Lynn, MA
Posts: 4,635 Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 4 Days 23 h 44 m 19 sec
Reputation Power: 81
Send a message via AIM to Hero Zzyzzx
I cringe when I see all those escaped quotes. HTML::Template is the way to go.

Reply With Quote
  #8  
Old August 28th, 2003, 01:01 AM
vous vous is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 14 vous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Sounds like something I should check out....any good sites to check out?

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Date validation with JavaScript inside a CGI script....not working!!

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap