HDRebel88
05-27-2012, 06:43 AM
I'm hoping this will be a simple javascript script, but I'm looking to have a dropdown menu generated based on what month is chosen in another dropdown menu. I also want the titles "Month", "Day", and "Year" to show up as the defaults on the dropdown menu, but when you click into the menu have them not be in the list. (A "title option" would be a nice addition to dropdown menus.)
How should this be done?
Here's the the relevant HTML code:
<p class="register_form_position_birthday">
Birthday:
<select>
<option>Month</option>
<option>January</option>
<option>February</option>
<option>March</option>
<option>April</option>
<option>June</option>
<option>July</option>
<option>August</option>
<option>September</option>
<option>October</option>
<option>November</option>
<option>December</option>
</select>
<select>
<option>Day</option>
</select>
<select>
<option>Year</option>
</select>
</p>
I have the following PHP page:
<?php
require_once 'function.php';
$month=$_GET['month'];
$year=$_GET['year'];
$test=generateBirthDayMenu($month,$year);
echo "<select name=\"day\">
<option>Day</option>
$test
</select>";
?>
And the following php function:
<?php
function generateBirthDayMenu($month,$year){
session_start();
$day_array=array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28);
$month_array1=array("April", "June", "September", "November");
$month_array2=array("January", "March", "May", "July", "August", "October", "December");
if($month=="February" && ($year % 4) ==0 && (($year % 100) !=0 || ($year % 400) ==0)){
array_push($day_array, "29");
}
foreach($month_array1 as $month_value){
if($month==$month_value){
array_push($day_array, "29", "30");
}
}
foreach($month_array2 as $month_value){
if($month==$month_value){
array_push($day_array, "29", "30", "31");
}
}
foreach($day_array as $day){
$day_menu.='<option value="'.$day.'"'; if(isset($_SESSION['birthday_day']) && $_SESSION['day']==$day){ $day_menu.=' selected="selected"'; } $day_menu.='>'.$day.'</option>'."\n";
}
return $day_menu;
}
?>
I'm assuming from here I need some way to fire off the function/PHP page and update the select field when the user selects the Month and/or Year. I know how to use AJAX, but I've never tried dropping it into a select/option menu before. How is this done?
How should this be done?
Here's the the relevant HTML code:
<p class="register_form_position_birthday">
Birthday:
<select>
<option>Month</option>
<option>January</option>
<option>February</option>
<option>March</option>
<option>April</option>
<option>June</option>
<option>July</option>
<option>August</option>
<option>September</option>
<option>October</option>
<option>November</option>
<option>December</option>
</select>
<select>
<option>Day</option>
</select>
<select>
<option>Year</option>
</select>
</p>
I have the following PHP page:
<?php
require_once 'function.php';
$month=$_GET['month'];
$year=$_GET['year'];
$test=generateBirthDayMenu($month,$year);
echo "<select name=\"day\">
<option>Day</option>
$test
</select>";
?>
And the following php function:
<?php
function generateBirthDayMenu($month,$year){
session_start();
$day_array=array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28);
$month_array1=array("April", "June", "September", "November");
$month_array2=array("January", "March", "May", "July", "August", "October", "December");
if($month=="February" && ($year % 4) ==0 && (($year % 100) !=0 || ($year % 400) ==0)){
array_push($day_array, "29");
}
foreach($month_array1 as $month_value){
if($month==$month_value){
array_push($day_array, "29", "30");
}
}
foreach($month_array2 as $month_value){
if($month==$month_value){
array_push($day_array, "29", "30", "31");
}
}
foreach($day_array as $day){
$day_menu.='<option value="'.$day.'"'; if(isset($_SESSION['birthday_day']) && $_SESSION['day']==$day){ $day_menu.=' selected="selected"'; } $day_menu.='>'.$day.'</option>'."\n";
}
return $day_menu;
}
?>
I'm assuming from here I need some way to fire off the function/PHP page and update the select field when the user selects the Month and/or Year. I know how to use AJAX, but I've never tried dropping it into a select/option menu before. How is this done?