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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2008
    Posts
    682
    Thanks
    114
    Thanked 2 Times in 2 Posts

    Editing User Info

    Here's a question what if I have an edit script that gets the users info and in that form has a drop down select menu. How do I get it to have the current value they are already selected?


    PHP Code:
    print '<tr>';
        print 
    '<td class=rowheading>Account:</td>';
        print 
    '<td class=row3><select name=enabled class=selection>';
        print 
    '<option value=1>Enabled<option value=0>Disabled</option>';
        print 
    '</select></td>';
        print 
    '</tr>'

  • #2
    Regular Coder Common's Avatar
    Join Date
    Jan 2009
    Location
    Glasgow, UK
    Posts
    133
    Thanks
    16
    Thanked 13 Times in 13 Posts
    If you put selected="selected" into the <option> tag that'll do as you ask. As for implementing, a simple:

    if($current_info == "this"){
    echo "<option value=\"selected\">";
    }

    kinda thing would do, you could put it in a function then wrap it round each one. I'm sure there'll be a more efficient (probably involving loops...) method, but this is how I do it.

    Edit: Btw, in case you didn't notice you'll need a </option> after "Enabled".


  •  

    Posting Permissions

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