Thank you Stuart. That did the trick. On Mon, Jul 18, 2011 at 10:38 PM, Stuart Dallas <stuart@xxxxxxxx> wrote: > On Tue, Jul 19, 2011 at 4:28 AM, Chris Stinemetz <chrisstinemetz@xxxxxxxxx> > wrote: >> >> Hello, >> >> I am building some select menu's dynamically from a mysql database and >> am courous how to give the menu a default option "Choose". >> >> Below is what I have so far for one of my menu's. >> >> Thank you in advace. >> >> <select name="market" id="market" >> onchange="javascript:get(this.parentNode);"> >> <?php >> foreach($market_prefix as $key => $value) >> { >> $selected = ''; >> if($value == $market) >> { >> $selected = 'selected'; >> } >> echo("<option value=$value $selected >> >$value : $market_name[$key]"); >> } >> ?> >> </select> > > Just add it as the first option. If none of the options have the selected > attribute, the first option will be the selected one. > I'd also recommend you escape the variables you're outputting, on the off > chance they contain HTML-like code. > <select name="market" id="market" onchange="if (this.value != '') { > javascript:get(this.parentNode); }"> > <option value="">Choose...</option> > <?php > foreach($market_prefix as $key => $value) > { > $selected = ''; > if ($value == $market) > { > $selected = 'selected'; > } > echo '<option value="', htmlspecialchars($value), '" ', $selected, '>', > htmlspecialchars($value.' : '.$market_name[$key]), '</option>'; > } > ?> > </select> > -Stuart > > -- > Stuart Dallas > 3ft9 Ltd > http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php