/    Sign up×
Community /Pin to ProfileBookmark

Submitting form

Hello:

I have a script which produces a calendar. The script contains drop down boxes for month and year. The drop down boxes are written within a form.

Right now, the script has the user click Go after they select the month and year. What I would like the script to do is when a person selects a month, the calendar automatically jumps to that month. I don’t want the user to click the Go button.

The script is written in PHP. The PHP forum suggested that JavaScript would allow me to accomplish this.

Can anyone help me out?

Thank you in advance.

Here is the script:
<?php
define(“ADAY”, (60*60*24));
if (!checkdate($_POST[‘month’], 1, $_POST[‘year’])) {
$nowArray = getdate();
$month = $nowArray[‘mon’];
$year = $nowArray[‘year’];
} else {
$month = $_POST[‘month’];
$year = $_
POST[‘year’];
}
$start = mktime (12, 0, 0, $month, 1, $year);
$firstDayArray = getdate($start);
?>
<html>
<head>
<title><?php echo “Calendar:”.$firstDayArray[‘month’].” “.$firstDayArray[‘year’] ?></title>
</head>
<body>
<form name=”drop” method=”post” action=”<?php echo “$_SERVER[PHP_SELF]”; ?>”>
<select name=”month”>
<?php
$months = Array(“January”, “February”, “March”, “April”, “May”, “June”, “July”, “August”, “September”, “October”, “November”, “December”);
for ($x=1; $x <= count($months); $x++) {
echo”<option value=”$x””;
if ($x == $month) {
echo ” SELECTED”;
}
echo “>”.$months[$x-1].””;
}
?>
</select>
<select name=”year”>
<?php
for ($x=1980; $x<=2010; $x++) {
echo “<option”;
if ($x == $year) {
echo ” SELECTED”;
}
echo “>$x”;
}
?>
</select>
<input type=”submit” value=”Go!”>
</form>
<br>
<?php
$days = Array(“Sunday”, “Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saturday”);
echo “<TABLE BORDER=1 CELLPADDING=5><tr>n”;
foreach ($days as $day) {
echo “<TD width=”10%” BGCOLOR=”#CCCCCC” ALIGN=CENTER><font face=”verdana” font size=”1″><strong>$day</strong></font></td>n”;
}
for ($count=0; $count < (6*7); $count++) {
$dayArray = getdate($start);
if (($count % 7) == 0) {
if ($dayArray[‘mon’] != $month) {
break;
} else {
echo “</tr><tr>n”;
}
}
if ($count < $firstDayArray[‘wday’] || $dayArray[‘mon’] != $month) {
echo “<td height=”100″ valign=”top” align=”right”><font face=”verdana” font size=”1″> </td>n”;
} else {
echo “<td height=”100″ valign=”top” align=”right”><font face=”verdana” font size=”1″>”.$dayArray[‘mday’].” </td>n”;
$start += ADAY;
}
}
echo “</tr></table>”;
?>

</body>
</html>

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @summit310 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...