The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Web Design
> JavaScript Development
|
Date validation with JavaScript inside a CGI script....not working!!
Discuss Date validation with JavaScript inside a CGI script....not working!! in the JavaScript Development forum on Dev Shed. Date validation with JavaScript inside a CGI script....not working!! JavaScript Development forum discussing JavaScript and DHTML, AJAX, and issues such as coding cross-browser JavaScript.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

August 27th, 2003, 09:32 AM
|
|
Junior Member
|
|
Join Date: May 2003
Posts: 14
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>";
|

August 27th, 2003, 09:41 AM
|
 |
kill 9, $$;
|
|
Join Date: Sep 2001
Location: Shanghai, An tSín
|
|
|
You'll have to be more specific than that. When it doesn't work, what does happen. What errors do you get?
|

August 27th, 2003, 09:49 AM
|
|
Junior Member
|
|
Join Date: May 2003
Posts: 14
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.
|

August 27th, 2003, 10:12 AM
|
 |
kill 9, $$;
|
|
Join Date: Sep 2001
Location: Shanghai, An tSín
|
|
|
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?
|

August 27th, 2003, 10:15 AM
|
|
Junior Member
|
|
Join Date: May 2003
Posts: 14
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?
|

August 27th, 2003, 12:57 PM
|
 |
An Ominous Coward
|
|
|
|
|
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!
|

August 27th, 2003, 02:46 PM
|
 |
11
|
|
Join Date: Jul 2001
Location: Lynn, MA
|
|
|
I cringe when I see all those escaped quotes. HTML::Template is the way to go.
|

August 28th, 2003, 01:01 AM
|
|
Junior Member
|
|
Join Date: May 2003
Posts: 14
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Sounds like something I should check out....any good sites to check out?
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|