RE: [PHP] combo boxes and default selected items
| From: | Chris | Date: | Tue, 30 Mar 2004 05:59:31 +0000 |
| Subject: | RE: [PHP] combo boxes and default selected items | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-181776@lists.php.net to get a copy of this message | ||
If it's a drop down (single item) I usually do:
<select name="month">
<option value="1"<?=1==$iMonth?'
selected="selected"':''?>>Jan</option>
<option value="2"<?=2==$iMonth?'
selected="selected"':''?>>Feb</option>
<option value="3"<?=3==$iMonth?'
selected="selected"':''?>>Mar</option>
</select>
If it's a multi, I do this:
<select name="month">
<option value="1"<?=in_array(1,$aMonth)?'
selected="selected"':''?>>Jan</option>
<option value="2"<?=in_array(2,$aMonth)?'
selected="selected"':''?>>Feb</option>
<option value="3"<?=in_array(3,$aMonth)?'
selected="selected"':''?>>Mar</option>
</select>
-----Original Message-----
From: Andy B [mailto:aborka1@wmis.net]
Sent: Monday, March 29, 2004 9:53 PM
To: php-general@lists.php.net
Subject: [PHP] combo boxes and default selected items
how would you go about making a selected item in a combo box??
<select name="month">
<option value="1">Jan</option>
<option value="2">Feb</option>
<option value="3">Mar</option>
</select>
for example on the combo box above how would i make the default select item
mar instead of jan??