1

Currently my dropdown looks as following:

$mon = array("Jan","Feb","Mar","Apr","May","Jun",
             "Jul","Aug","Sep","Oct","Nov","Dec");

$output="<table border='0' cellspacing='0' cellpadding='0'>
<tr class = 'tit'>
<td>Select Month
<select name='month' onChange='dateShow($infrasId,1)' id='month'>";
for($i = 1; $i <= 12; $i ++) {
    $output.="<option value='$i'>".$mon[$i-1]."</option>";
} 
$output.="</select>";

I am getting the value of month through URL to a variable $month.

How can I select that month by default?

2
  • 1
    is that full code ? can you make your question more clearly Commented Mar 12, 2014 at 12:49
  • Did you not put a closing bracket (}) on the if on purpose? Commented Mar 12, 2014 at 12:55

1 Answer 1

3

i didn't understand your question very well but i think this is what you are looking for

$output.="<option value='$i' " . ( mon[$i] == $_POST['month'] ? "selected" : "" ) . ">".$mon[$i-1]."</option>";

replace $_POST['month'] with requested month name variable

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.