Tuesday, 28 May 2013

get selected month value in dropdown list if using an array

get selected month value in dropdown list if using an array

I am trying to get the selected value in the drop down; but the items inside it are in an array. How can I select that?
For now, I have these lines of code:
<?php
// lowest year wanted
$cutoff = 2013;

// current year
$now = date('Y');

// build months menu
echo '<select name="month">' . PHP_EOL;
for ($m=1; $m<=12; $m++) {
    echo '  <option value="' . $m . '">' . date('M', mktime(0,0,0,$m)) . '</option>' . PHP_EOL;
}
echo '</select>' . PHP_EOL;

// build days menu
echo '<select name="day">' . PHP_EOL;
for ($d=1; $d<=31; $d++) {
    echo '  <option value="' . $d . '">' . $d . '</option>' . PHP_EOL;
}
echo '</select>' . PHP_EOL;

// build years menu
echo '<select name="year">' . PHP_EOL;
for ($y=$now; $y>=$cutoff; $y--) {
    echo '  <option value="' . $y . '">' . $y . '</option>' . PHP_EOL;
}
echo '</select>' . PHP_EOL;
?>
I want to get the selected Month. Any idea?

No comments:

Post a Comment