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

Thread: combo

  1. #1
    New Coder
    Join Date
    Feb 2007
    Posts
    92
    Thanks
    1
    Thanked 0 Times in 0 Posts

    combo

    I have a combo box :

    Code:
    <select name="stock" id="stock">
            <option value="In Stock">In Stock</option>
            <option value="Not in Stock">Not in Stock</option>
            <option value="Discontinued">Discontinued</option>
            </select>
    I am connecting to the database and i want to display the results in a form and change the value of the combo box to the one value in the database for that record.

    How would i set the combo box to the correct value using php.
    Im not sure if this is a html or a php question

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Both actually, you just have to add "selected" inside of the option tag. You can use an if() switch or ternary operator to do it with, it's pretty straight-forward.
    PHP Code:
    <option value="1"<?=!empty($selected) ? ' selected' '';?>>Selection</option>

  • #3
    New Coder
    Join Date
    Feb 2007
    Posts
    92
    Thanks
    1
    Thanked 0 Times in 0 Posts
    The problem i have is i dont know where i should do an if statement and how to construct it to check each option for it's value.
    would i do it within the <option> tag or above the <select> tag and how do you refer to the html tags within php?

    I havent a clue how to do this!

    thanks

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    I just showed you in my previous post. You have to make one for each option.


  •  

    Posting Permissions

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