Alright, I;ve been staring at this forever and I can;t seem to find the problem.
I've got a GET variable called $_GET['mailbox']. this variable is either equal to 'Inbox', 'Sent_Items', 'Drafts', or 'Deleted_Items'.
I have this code for a select box:
PHP Code:
<select name="mailbox" class="mbox" onchange="listThem()">
<option>--Select a Mailbox--</option>
<?
$get_var = trim($_GET['mailbox']);
print selectMailbox('Inbox',$get_var);
print selectMailbox('Sent_Items',$get_var);
print selectMailbox('Drafts',$get_var);
print selectMailbox('Deleted_Items',$get_var);
?>
</select>
And this function that builds the <option> tag content:
// Select Mailbox function
PHP Code:
function selectMailbox($mailbox, $get_var)
{
$output .= '<option value="' . $mailbox . '" ';
if ($mailbox == 'Inbox')
{
if (empty($get_var) && empty($_SESSION['mailbox']))
{
$output .= 'selected="selected"';
}
}
elseif ($get_var == $mailbox)
{
unset($_SESSION['mailbox']);
$_SESSION['mailbox'] = $get_var;
$output .= 'selected="selected"';
}
elseif ($_SESSION['mailbox'] == $mailbox)
{
$output .= 'selected="selected"';
}
$output .= '>' . str_replace("_"," ",$mailbox) . '</option>';
return $output;
}
The problem is, when $_GET['mailbox'] = 'Inbox' and $mailbox = 'Inbox', the code inside this conditional:
PHP Code:
elseif ($get_var == $mailbox)
{
unset($_SESSION['mailbox']);
$_SESSION['mailbox'] = $get_var;
$output .= 'selected="selected"';
}
is NOT executed. Inbox is NOT made the selected option in the select menu for some reason.
Also, when $_GET['mailbox'] = 'Inbox', the relevant source code looks like this:
Code:
<select name="mailbox" class="mbox" onchange="listThem()">
<option>--Select a Mailbox--</option>
<option value="Inbox" >Inbox</option><option value="Sent_Items" >Sent Items</option><option value="Drafts" >Drafts</option><option value="Deleted_Items" >Deleted Items</option>
</select>
You can see that the option with value 'Inbox' is not selected as it should be.
Also, I've echoed out the variables, and everything checks out OK.
Can anyone see the problem? thanks.