I'm taking this as an opportunity to teach myself some JavaScript, so I've been working on this all afternoon. It's not finished, and won't be till Monday, but here's what I've got so far (below). The only thing that doesn't work is emptying the options when you change the month, but so far it almost accomplishes your goal.
Here's 'test.php':
<?php
if ( $_GET['value'] === 0 OR ! empty($_GET['value']) )
{
$month = (int) $_GET['value'];
$days = 0;
$options = '';
switch($month)
{
case 0: $days = 31; break;
case 1: $days = 29; break;
case 2: $days = 31; break;
case 3: $days = 30; break;
case 4: $days = 31; break;
case 5: $days = 30; break;
case 6: $days = 31; break;
case 7: $days = 31; break;
case 8: $days = 30; break;
case 9: $days = 31; break;
case 10: $days = 30; break;
case 11: $days = 31; break;
}
for($i = 1; $i <= $days; $i++)
{
if($i < $days) {
$options .= "$i,";
} else {
$options .= "$i";
}
}
echo $options;
}
?>
and here's the 'ajax.js' file:
xmlhttp = new XMLHttpRequest();
function makerequest(serverpage)
{
day = document.getElementById('day');
//code I was working on before stopping
/*if(day)
{
if(day.length > 0)
{
for(a = 1; a <= day.length; a++)
{
day.remove(a);
}
}
}*/
xmlhttp.open("GET",serverpage);
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
day.setAttribute('style','display:block');
var preconvoptions = xmlhttp.responseText;
var options = preconvoptions.split(',');
for(i = 1; i <= options.length; i++)
{
var newOpt = document.createElement('option');
newOpt.text = i;
newOpt.value = i;
day.add(newOpt, null);
}
console.log(xmlhttp.responseText);
}
}
xmlhttp.send(null);
}
Finally, here's the index.php (I separated the HTML from the PHP file that generates the request):
<html lang="en">
<head>
<script type="text/javascript" src="ajax.js"></script>
</head>
<body>
<form method="post" action="">
<select name="s" onchange="makerequest('test.php?value='+ this.value)">
<option value="">Select One</option>
<option value="0">January</option>
<option value="1">February</option>
<option value="2">March</option>
<option value="3">April</option>
<option value="4">May</option>
<option value="5">June</option>
<option value="6">July</option>
<option value="7">August</option>
<option value="8">September</option>
<option value="9">October</option>
<option value="10">November</option>
<option value="11">December</option>
</select>
<br/>
<select id='day' name='day' style="display:none;">
</select>
<input type="submit" name="submit" value="go" />
</form>
</body>
</html>
The steps I go through in this app are as follows:
1. Hide the select option that will receive the number of days
2. When the Month select box changes, send that value to 'test.php' to make a comma-separated list of numbers representing the number of days for the chosen month. Then send back that comma-separated list.
3. Take the response text and convert it to an array using the
split method
4. Change the
display property of the 'day' select element to
block so it's shown
5. Iterate through that array and create the
option tags with values and text.
I'm still learning this as well, so I wouldn't recommend just copying and pasting for production. This will hopefully get you on your way.
Here's a good page I used in working this out for myself.