This code will select the current month and have it appear as the first shown option in the dropdown. Very handy for forms.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<label for="dropdown1" id="labelreport">REPORT MONTH?</label> <select name="reportmonth" type="hidden" id="reportmonth" class="form-control"> <?php for ($i = 0; $i <= 12; ++$i){ $time = strtotime(sprintf('+%d months', $i)); $label = date('M ', $time); $value = date('M', $time); echo '<option value="'.$value.'" '; if((isset($_GET['month']))&&($value==$_GET['month']))echo 'selected';// Check if form submitted or not. select the month if yes echo '>'.strtoupper($label).'</option>'; } ?> </select> |