Option Selected="selected"

ayesha789

This code is about months and year options.
When you change the months or Year and press Submit button it will show selected month and year which you sleclet.
This will be helpful for you all.

122 Views
About the Author
<form action="/forums/same_page.php" method="post" name="form">
<? 
if(isset($_REQUEST['btn']))// if submit btn is pressed
	{
		
	
$m = $_POST["months"]; 

	($m == 'January')? $std1='selected="selected"':$std1='';
	($m == 'February')? $std2='selected="selected"':$std2='';
	($m == 'March')? $std3='selected="selected"':$std3='';
	($m == 'April')? $std4='selected="selected"':$std4='';
	($m == 'May')? $std4='selected="selected"':$std5='';
	($m == 'June')? $std6='selected="selected"':$std6='';
	($m == 'July')? $std7='selected="selected"':$std7='';
	($m == 'August')? $std8='selected="selected"':$std8='';
	($m == 'September')? $std9='selected="selected"':$std9='';
	($m == 'October')? $std10='selected="selected"':$std10='';
	($m == 'November')? $std11='selected="selected"':$std11='';
	($m == 'December')? $std12='selected="selected"':$std12='';
	
$y = $_POST["years"];
	($y == '2010')? $stdy1='selected="selected"':$stdy1='';	
	($y == '2011')? $stdy2='selected="selected"':$stdy2='';
	($y == '2012')? $stdy3='selected="selected"':$stdy3='';
	($y == '2013')? $stdy4='selected="selected"':$stdy4='';
	($y == '2014')? $stdy5='selected="selected"':$stdy5='';
	($y == '2015')? $stdy6='selected="selected"':$stdy6='';
	($y == '2016')? $stdy7='selected="selected"':$stdy7='';
	}
?>
<select name="months" style="border-width: 1px;
    border-style: solid;
    border-color: #61A0CE;
	background-image: url(c.jpg);
    background-repeat: no-repeat;
	background-position: center;
	font-family: Arial, Helvetica, sans-serif;
    font-size: 10px;
    color: #333333;
    width: 80px;
    height: 13px;" >
	 <optgroup label="Months" style="background-color:#999999; font-weight:bold">
  <option <? echo $std1; ?> value="January" >January</option>
  <option <? echo $std2; ?> value="February" >February</option>
  <option <? echo $std3; ?> value="March" >March</option>
  <option <? echo $std4; ?> value="April">April</option>
  <option <? echo $std5; ?> value="May" >May</option>
  <option <? echo $std6; ?> value="June">June</option>
  <option <? echo $std7; ?> value="July">July</option>
  <option <? echo $std8; ?> value="August">August</option>
  <option <? echo $std9; ?> value="September">September</option>
  <option <? echo $std10; ?> value="October">October</option>
  <option <? echo $std11; ?> value="November">November</option>
  <option <? echo $std12; ?> value="December">December</option>
   </optgroup>
</select>

<select name="years" style="border-width: 1px;
    border-style: solid;
    border-color: #61A0CE;
	background-image: url(c.jpg);
    background-repeat: no-repeat;
	background-position: center;
	font-family: Arial, Helvetica, sans-serif;
    font-size: 10px;
    color: #333333;
    width: 60px;
    height: 13px;">
	 <optgroup label="Year" style="background-color:#999999; font-weight:bold">
  <option <? echo $stdy1; ?> value="2010" selected="selected">2010</option>
  <option <? echo $stdy2; ?> value="2011">2011</option>
  <option <? echo $stdy3; ?> value="2012">2012</option>
  <option <? echo $stdy4; ?> value="2013">2013</option>
  <option <? echo $stdy5; ?> value="2014">2014</option>
  <option <? echo $stdy6; ?> value="2015">2015</option>
  <option <? echo $stdy7; ?> value="2016">2016</option>
	</optgroup>
</select>


<input name="btn" type="submit" Style="width: 50px;
	height: 15px;
	margin-left:0px;
	cursor: pointer;
	border: none;
	background: transparent url(/images/eimssearch.jpg) no-repeat 0 0;" value="" />
</form>