Hi,
Is it possible to have a certain value of a drop-down box be selected automatically? For example, in my logging system, everytime someone wants to edit an entry, the date gets reset (I have month, day, and year drop down boxes). All of those boxes are hard coded... is it even possible to do what I want to do?
Thanks,
- Jeff
Autoselect Drop Down Values
Moderator: General Moderators
-
ibanez270dx
- Forum Commoner
- Posts: 74
- Joined: Thu Jul 27, 2006 12:06 pm
- Location: Everywhere, California
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
This isn't really PHP..
Code: Select all
<select name="foo">
<option value="something">foo!</option>
<option value="something" selected="selected">foo?</option>
<option value="something">foo^</option>
</select>Yes, just use "selected" like so
Code: Select all
<select name="foo">
<option value="else">something</option>
<option value="devnetwork" selected="selected">php</option>
<option value="nice">isntthis</option>
</select>-
ibanez270dx
- Forum Commoner
- Posts: 74
- Joined: Thu Jul 27, 2006 12:06 pm
- Location: Everywhere, California
Thanks - but there is a problem with it. My Select Boxes are hard coded and I need the PHP to decide which option is selected... here is my code: Currently, it autoselects "No Crew" every time....
HTML:
Anyone know what I'm doing wrong or what I can do to fix this?
Thanks,
- Jeff
Code: Select all
if($dwntime_type == "unscheduled")
{
$unscheduled_s = "selected";
}
if($dwntime_type == "progressive")
{
$progressive_s = "selected";
}
if($dwntime_type == "No Crew")
{
$nc_s = "selected";
}HTML:
Code: Select all
<select tabindex=1 name="dwntime_type" size="1" width="107">
<option value="scheduled">Scheduled</option>
<option value="unscheduled" selected="<? echo $unscheduled_s; ?>">Unscheduled</option>
<option value="progressive" selected="<? echo $progressive_s; ?>">Progressive</option>
<option value="nc" selected="<? echo $nc_s; ?>">No Crew</option>
</select>Thanks,
- Jeff
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
it's because you have the selected attribute in all of them.Can you guess what you're supposed to put in each now? 
Code: Select all
<select tabindex=1 name="dwntime_type" size="1" width="107">
<option value="scheduled">Scheduled</option>
<option value="unscheduled" <?php echo $unscheduled_s; ?>>Unscheduled</option>
<option value="progressive" <?php echo $progressive_s; ?>>Progressive</option>
<option value="nc" <?php echo $nc_s; ?>>No Crew</option>
</select>-
ibanez270dx
- Forum Commoner
- Posts: 74
- Joined: Thu Jul 27, 2006 12:06 pm
- Location: Everywhere, California