|
|
|
2.
Using the lite sample.lib in a web page
<html>
<head>
<title>
</title>
<script language="javascript">
<!-- begin hiding
function dataValidate()
{
daysInMonth = new makeArray( 12 );
daysInMonth[0] = 31;
daysInMonth[1] = 28;
daysInMonth[2] = 31;
daysInMonth[3] = 30;
daysInMonth[4] = 31;
daysInMonth[5] = 30;
daysInMonth[6] = 31;
daysInMonth[7] = 31;
daysInMonth[8] = 30;
daysInMonth[9] = 31;
daysInMonth[10] = 30;
daysInMonth[11] = 31;
// get the year
for( var i = 0; i < 4; i++ )
{
if( document.forms[0].year_[i].selected )
{
tmYear = document.forms[0].year_[i].value;
break;
}
}
// get the month
for( var i = 0; i < 12; i++ )
{
if( document.forms[0].month_[i].selected )
{
tmMon = document.forms[0].month_[i].value;
break;
}
}
if( tmMon == 1 )
{
if( isLeap( tmYear ) )
{
daysInMonth[tmMon] = 29;
}
}
// get the day
tmDay = document.forms[0].day_.value;
// check the day
if( tmDay > daysInMonth[tmMon] || tmDay < 1 )
{
errStr = "Day must be an integer from 1 to " + daysInMonth[tmMon] + ".";
alert( errStr );
return false;
}
return true;
}
function makeArray( n )
{
this.length = n;
for( var i = 0; i < n; i++ )
{
this[i] = 0;
}
return this;
}
function isLeap( year )
{
if( ( year % 400 == 0 ) || ( ( year % 4 == 0 ) && ( year % 100 != 0 ) ) )
return true;
else
return false;
}
// end hiding -->
</script>
</head>
<body>
<form action="/cgi-bin/w3-msql/~matthew/sample/post.html"
method=post onSubmit="return dataValidate()">
<!
load "sample.lib";
datePrompt( "", -1, -1, -1 );
>
<p><input type="submit" value="Go"></p>
</form>
</body>
</html>
3. Open the webpage: http://localhost/cgi-bin/w3-msql/~matthew/sample.html 4.
Script to handle the POST method
<html>
<head>
<title>
</title>
<script language="javascript">
<!-- begin hiding
// end hiding -->
</script>
</head>
<body>
<h2>Form Results</h2>
<!
load "sample.lib";
printf( "<p>%s %s, %s</p>", monthtostr( (int)$month_ ), $day_, $year_ );
>
</body>
</html>
|
|
|
|
|
Last Modified: 17 December 1997 St. Louis Unix Users Group - Linux SIG |
|