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 5 of 5

Thread: Option value 0

  1. #1
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Option value 0

    I have a drop down list filling itself from my database. All of the items (names, actually) show up nicely, however I want the first item to be Choose..., or Select..., not the first item/name on the list. When I try to enter <option value="0">Choose... anywhere in the code, with or without the end tag </option>, the word Choose... appears above EVERY item/name in the list! I know how to do this with a manual list, but not with one drawing from a database. Does anyone out there know how to do this?

    Here's the code:

    <label><b>Select Counselor: </b></label><select name="counselor" size="1">
    <?php
    do {
    ?>
    <option value="<?php echo $row_counselor['name']?>"<?php if (!(strcmp($row_counselor['name'], $row_counselor['name'])))?>><?php echo $row_counselor['name'];?></option>
    <?php
    } while ($row_counselor = mysql_fetch_assoc($counselor));
    $rows = mysql_num_rows($counselor);
    if($rows > 0) {
    mysql_data_seek($counselor, 0);
    $row_counselor = mysql_fetch_assoc($counselor);
    }
    ?>
    </select>



    Thanks.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    This isn't something in PHP, its an HTML thing.
    Use the <optgroup> tag, and add a label for "Choose". This adds a display for the choose, but makes it unselectable, which means you never need to worry about it:
    PHP Code:
    <label><b>Select Counselor: </b></label><select name="counselor" size="1">
    <optgroup label="Choose">
    <?php // do php stuff ?>
    </optgroup>
    </select>
    Something like that.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi Fou-Lu,
    Thanks. I did try your suggestion, and it did put a Choose at the top of my list, but the first name on the list still appears in the list box, not Choose. I don't see Choose until I drop down the list, then I have to nudge up to the top to see it listed first in the list. Maybe it can't be done.

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Just put your choose option before the do..while loop.

    Though I have to ask, isn't it obvious to your user that he/she needs to choose? Why even put that in the list? If you want the listbox to not have anything selected initially, use javascript to select the -1 index of the listbox.

  • #5
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you, Fumigator for your response. Yes, that was the answer, to put the choose option before the loop. I had been putting it inside. (I'm still really new to this.)

    The reason that I want a choose option is that the output from the form goes to a confirmation page, and if a selection is not made for certain entries (this is one of them), I want a message to appear that tells the user that they need to go back and make a selection. Without the Choose option, which gives the 0 output, the name of the first counselor appears, which may or may not be the correct entry. This way if the output is 0, I can tell them to go make a choice. Thanks again for your help.


  •  

    Posting Permissions

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