...

View Full Version : Setting Default Drop Down Value



climertech
09-13-2011, 09:36 PM
Hello All,

I have a script i'm working on where information is submited and so forth,

But i also have an edit page that when the info is pulled i want the default values set on the form,for the most part this is working fine except for drop downs


Basically i'm pulling MYSQL values and based on those setting the default drop down value for a field which so far hasn't been successful



Thanks,

Sparchy
09-13-2011, 09:41 PM
hello climertech

you could try something like this


<option <?php echo $var =='whatever' ? 'selected' : ''?>>whatever</option>

i hope that helps ya

Sparchy

BluePanther
09-13-2011, 09:55 PM
hello climertech

you could try something like this


<option <?php echo $var =='whatever' ? 'selected' : ''?>>whatever</option>

i hope that helps ya

Sparchy

That, except for xhtml doctypes the correct usage would be:


echo '<option value="value"'.(($field == 'current option value') ? ' selected="selected">' : '>').$field.'</option>';


Just an FYI, if you've not seen that ? comparison before, it's called a ternary comparison - you can find it in the php comparison manual :). It's basically an if else statement following this format:


(condition) ? TRUE : FALSE



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum