Empty Default Value for Select Tag When An Option Evaluates to Zero

Hello,

I have a select tag where the options are an array('0' => 'Inactive', '1' => 'Active'). I want the select box to initially be the empty value, but it always defaults to "Inactive", e.g. this code:

$options = array('0' => 'Inactive', '1' => 'Active');
echo $this->tag->selectStatic(array('active', $options, 'useEmpty' => true, 'emptyValue' => '', 'value' => ''));

Outputs this:

<select id="active" name="active">
    <option value="">Choose...</option>
    <option selected="selected" value="0">Inactive</option>
    <option value="1">Active</option>
</select>

How can I get it to default to the empty option?

Thanks in advance for your help!



30.8k

Hey

You try this:

echo $this->tag->selectStatic(array('active', $options, 'useEmpty' => true, 'emptyValue' => '', 'value' => '3'


995

Hi Thien,

Thank you for that suggestion, it works. I'm going to accept your answer, although this seems like a bit of a hack (no offense, I appreciate your help).