Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Setting Default Drop Down Value

    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,

  • #2
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hello climertech

    you could try something like this

    PHP Code:
    <option <?php echo $var =='whatever' 'selected' ''?>>whatever</option>
    i hope that helps ya

    Sparchy

  • #3
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Quote Originally Posted by Sparchy View Post
    hello climertech

    you could try something like this

    PHP Code:
    <option <?php echo $var =='whatever' 'selected' ''?>>whatever</option>
    i hope that helps ya

    Sparchy
    That, except for xhtml doctypes the correct usage would be:
    PHP Code:
    echo '<option value="value"'.(($field == 'current option value') ? ' selected="selected">' '>').$field.'</option>'
    Edit:
    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:
    PHP Code:
    (condition) ? TRUE FALSE 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •