How to set default value for dropdown menu - simple html form - mysql variable

Discussion in 'HTML & Website Design' started by peppy, Jun 25, 2010.

  1. #1
    Greetings,

    I have a small problem. I am trying to set a default for a dropdown menu on a page where people edit their profiles.

    Here is the code I have, which is not working:

    <select name="status" value="<?php echo $oldstatus; ?>" >
                    <option value=""></option>
                    <option value="Away">Away</option>
                    <option value="Online">Online</option>
                    <option value="Offline">Offline</option>
    </select>
    PHP:
    I would like the old status to be displayed so the person doesn't have to reselect a status. Please let me know if you can figure this out.

    Thank yo
     
    peppy, Jun 25, 2010 IP
  2. peppy

    peppy Active Member

    Messages:
    389
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    95
    #2
    Nevermind, I got it.

    I have to apologize. I sit here for 3 hours trying to figure this out, then as soon as I create a new thread here, I figure it out seconds later... sorry
     
    peppy, Jun 25, 2010 IP
  3. rohitvipin

    rohitvipin Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    <tr>
    <td>Status: </td>
    <td><select name="Status">
    <option value="online" <?php if($_REQUEST['Status']=='online') echo "selected='selected'";?>>online</option>
    <option value="offline" <?php if($_REQUEST['State']=='offline') echo "selected='selected'";?>> offline</option>
    <option value="busy" <?php if($_REQUEST['State']=='busy') echo "selected='selected'";?>> busy</option>
    </select>
    </td>
    </tr>
     
    rohitvipin, Jul 7, 2011 IP
  4. DhirajSaini

    DhirajSaini Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    <select name="status" value="<?php echo $oldstatus; ?>" >
    <option value=""></option>
    <option value="Away">Away</option>
    <option value="Online">Online</option>
    <option value="Offline">Offline</option>
    </select>
     
    DhirajSaini, Jul 8, 2011 IP
  5. Warrichpk

    Warrichpk Banned

    Messages:
    192
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    28
    #5
    hello
    first of all ill tell you this The <select> tag is used to create a select list (drop-down list).

    The <option> tags inside the select element define the available options in the list.
    example :
    <select>
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
    <option value="mercedes">Mercedes</option>
    <option value="audi">Audi</option>
    </select>
    try it
     
    Warrichpk, Jul 11, 2011 IP
  6. Anastasiia

    Anastasiia Peon

    Messages:
    9
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Oh, I had the same problem!
     
    Anastasiia, Jul 13, 2011 IP
  7. unknownpray

    unknownpray Active Member

    Messages:
    3,831
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    70
    #7
    dear you can check this code
    you can try <select name="vehicle" value="<?php echo $oldstatus; ?>" >
    <option value=""></option>
    <option value="hero honda">hero honda</option>
    <option value="Pulsur">Pulsur</option>
    <option value="Honda">Honda</option>
    </select>
     
    unknownpray, Jul 25, 2011 IP
  8. gauravchhn63

    gauravchhn63 Greenhorn

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #8
    Dear please try this code.. i have to done with this code.
    <select id="status" name="status" value="<?php echo $oldstatus; ?>">
    <option value=""></option>
    <?php
    /* Type Select Query for Status and get Status ID from Get value and from Query */
    foreach($my_status as $key=>$val){ ?>
    <option value="<?=$val['status_id']?>" <?php echo ($my_status_id[0]['status_id'] == $val['status_id']) ? 'selected="selected"' : '';?>><?=$val['status']?></option>
    <?php } ?>
    </select>
     
    gauravchhn63, May 14, 2013 IP