Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

default selecting form options

Status
Not open for further replies.

SM777

Technical User
Joined
Mar 7, 2001
Messages
208
Location
GB
I have a form in a php page

<select name=&quot;day&quot;>
<option value=&quot;Mon&quot;>Monday</option>
.
.
.
<option value=&quot;Sun&quot;>Sunday</option>

What I want to do is to make todays day the default. So that if today is Sunday then the last line would become:

<option value=&quot;Sun&quot; selected>Sunday</option>

How do I do this?




 
this should work
-------------------------
<?php

$nowday = date(&quot;D&quot;);

$weekdays=array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
echo &quot;<select>\n&quot;;
foreach ($weekdays as $w_day){
if ($nowday == $w_day){
echo &quot;<option \&quot;$w_day\&quot; selected>$w_day</option>\n&quot;;
}else{
echo &quot;<option \&quot;$w_day\&quot;>$w_day</option>\n&quot;;
}

}
echo &quot;</select>\n&quot;;

?> ***************************************
Party on, dudes!
[cannon]
 
good stuff, cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top