LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-27-2003, 09:28 AM   #1
vous
Member
 
Registered: Mar 2003
Location: Macondo
Distribution: Mandrake 9.1, 10.1, SuSE 8.1 pro, 10.1, Red Hat 8.0/9.0
Posts: 380

Rep: Reputation: 30
JavaScript inside a CGI script for date validation....doesn't work!!


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

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.

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>";

Last edited by vous; 08-27-2003 at 09:52 AM.
 
Old 08-27-2003, 12:17 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
Check the source of the page once it is created. Some od hte text has probably been assumed to be variables. ie the $ signs.
 
Old 08-27-2003, 04:34 PM   #3
Looking_Lost
Senior Member
 
Registered: Apr 2003
Location: Eire
Distribution: Slackware 12.0, OpenSuse 10.3
Posts: 1,120

Rep: Reputation: 45
I only dabble lightly with html and javascript but an easy way to check if a date is valid is to have three different text inputs for day,month and year , parseInt the three different values and try to create a new Date object
with them, if the new Date object contains "Invalid Date" then you know it's a dodgy date.

Just something to ponder I guess.
 
Old 08-27-2003, 04:49 PM   #4
Looking_Lost
Senior Member
 
Registered: Apr 2003
Location: Eire
Distribution: Slackware 12.0, OpenSuse 10.3
Posts: 1,120

Rep: Reputation: 45
I guess I should spend a bit more time dabbling - still got to do the range checking like you're doing - oh well
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to print my CGI programs output inside an HTML zaveko Programming 9 10-11-2005 05:37 PM
Javascript Code doesnt work w/ firefox? swatward Programming 1 04-18-2005 06:54 PM
CGI to work out side of cgi-bin? crashedspine Linux - Newbie 13 09-02-2004 08:49 PM
How do I get javascript to work with Opera? Aerlock Linux - Software 0 11-17-2003 09:28 PM
JavaScript applets not work in Linux? Conman Linux - Newbie 2 07-27-2002 12:41 AM


All times are GMT -5. The time now is 01:23 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration