Forums
This topic is locked
Dynamic Lists
Posted 04 Jun 2002 09:57:51
1
has voted
04 Jun 2002 09:57:51 Andrew Eldon posted:
I have a Scheduling system on my company website that employees can use to post their schedules. It works great, but it's missing one thing.They can choose a different month by selecting it from a Drop Down Menu - however the default on the menu is always 01. How do I make the drop down list display the current month as the initially selected value.
Something to do with variables I'm sure.
Thanks in advance,
Andrew
Replies
Replied 04 Jun 2002 18:45:36
04 Jun 2002 18:45:36 Tim Green replied:
A little lateral thinking was needed for this one... You do have two options, you could check the current month variable using the PHP date() command, on each line, but I find this method a little untidy.
Here's how I would achieve this...
<pre id=code><font face=courier size=2 id=code>
<select name="month">
<?php for ($k=0; $k < 12; $k++) {
$currMonth = date("m"
$theValue = $k;
if ($k < 10) {
$theValue = "0" . $theValue;
}
if ($theValue == $currMonth) {
$selText = "selected";
} else {
$selText = "";
}
?>
<option value="<?php echo $theValue; ?>" <?php echo $selText; ?>><?php echo $theValue; ?></option>
<?php } ?>
</select>
</font id=code></pre id=code>
I've basically built up all your options for the select statement using a for..next loop, which is a little more efficient.
I hope this helps.
Tim Green
Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
Here's how I would achieve this...
<pre id=code><font face=courier size=2 id=code>
<select name="month">
<?php for ($k=0; $k < 12; $k++) {
$currMonth = date("m"
$theValue = $k;
if ($k < 10) {
$theValue = "0" . $theValue;
}
if ($theValue == $currMonth) {
$selText = "selected";
} else {
$selText = "";
}
?>
<option value="<?php echo $theValue; ?>" <?php echo $selText; ?>><?php echo $theValue; ?></option>
<?php } ?>
</select>
</font id=code></pre id=code>
I've basically built up all your options for the select statement using a for..next loop, which is a little more efficient.
I hope this helps.
Tim Green
Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
Replied 05 Jun 2002 04:22:21
05 Jun 2002 04:22:21 Andrew Eldon replied:
Thanks Tim - works a charm!
Andrew
Andrew