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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post

    Post Drop down box for text color

    Good day to you all,
    I'm trying to find a code for a drop down box displaying a color.
    It would show different colored bar, and their value would be the color code example: "#003366".

    The valu would then be $_post

    Can somebody help me ?
    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
    Do you have a specified colour set you want to use, or every possible combination between 000000 and FFFFFF? Just cause that can get awefully long...
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post
    I just want black, white, couple blue, beige.

  • #4
    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
    Oh, ok this isn't really a php issue then since its so few its easy to hard code.
    Obviously you know the general code to use:
    Code:
    <select ...>
      <option value="000000" id="opt000000">#000000</option>
      <option value="F5F5DC" id="optF5F5DC">#F5F5DC</option>
      <option value="FFFFFF" id="optFFFFFF">#FFFFFF</option>
      <option value="0000FF" id="opt0000FF">#0000FF</option>
    </select>
    Not sure what blues and stuff, but the f5f5dc is your beige.
    Anyway, change the colour using css like so:

    Code:
    option#opt000000 { background-color: #000000; color: #FFFFFF;}
    option#opt0000FF { background-color: #0000FF; color: #FFFFFF;}
    option#optF5F5DC { background-color: #F5F5DC; color: #000000;}
    option#optFFFFFF { background-color: #FFFFFF; color: #000000;}
    As you can see, this is rather repetative. But since this isn't a php concern, best to check out the javascript forum for a method that can iterate all of the select items and specify their background and forground colours. Its simple to do, but I don't trust my off the cuff javascript to suit your purposes
    Good luck!

    Edit:
    Sorry my bad, I completely missed your php question lol
    $_POST will send a value back, in my above example it sends the colour code. Now, in php you must store the values in an array or whatever you want to use, and construct the colour options from there:
    PHP Code:
    $colourArray = array("000000""F5F5DC""FFFFFF""0000FF");
    for (
    $i 0$i count($colourArray); $i++)
    {
        
    $selected = ($colourArray[$i] == trim($_POST['COLOUR_CHOICE'])) ? ' selected="selected"' '';
        echo 
    '<option value="' $colourArray[$i] . '"' $selected  '>#' $colourArray[$i] . '</option>';


    I didn't test this out, but seems to work out ok in my head, lol
    Change COLOUR_CHOICE to whatever name is given to your select element.
    Last edited by Fou-Lu; 06-07-2007 at 05:11 AM.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #5
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post
    good, but I need a colored bar to be shown not the code or the name.
    Thanks !

  • #6
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    Peuplarchie....I believe that option value ID and the CSS that it corresponds to will set the background color for each option value. You could enter text into the option box the same color as the background, such as:

    Code:
    option#optF5F5DC { background-color: #F5F5DC; color:#F5F5DC;}
    If there is no text in an option box then the option box is very small, text like qwerty will provide a good width.

    Code:
    <option value="F5F5DC" id="optF5F5DC">qwerty</option>
    Leonard Whistler

  • #7
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    or just several &nbsp;s

    Or, to be nice to people, you could write the name of the color

    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #8
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post
    Yes, sorry I misread your answer lol ..
    It's working perfectly!!!

  • #9
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post
    But I cannot in the select box have the name instead of the color code as the choice ?

  • #10
    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
    Yes.
    Not sure what your using exactly, so back to my code :P
    PHP Code:
    $colourArray = array("000000""F5F5DC""FFFFFF""0000FF");
    for (
    $i 0$i count($colourArray); $i++)
    {
        
    $selected = ($colourArray[$i] == trim($_POST['COLOUR_CHOICE'])) ? ' selected="selected"' '';
        echo 
    '<option value="' $colourArray[$i] . '"' $selected  '>#' $colourArray[$i] . '</option>';

    We'll change the colourArray to be multidimensional:
    PHP Code:
    $colourArray = array("Black" => "000000""Beige" => "F5F5DC""White" => "FFFFFF""Blue" => "0000FF"); 
    Then edit the for loop like so:
    PHP Code:
        $selected = ($colourArray[$i][1] == trim($_POST['COLOUR_CHOICE'])) ? 'selected="selected"' '';
        echo 
    '<option value="' $colourArray[$i][1] . '"' $selected '>' $colourArray[$i][0] . '</option>'
    There you go.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #11
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post
    it dont work

  • #12
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post
    Your first code was perfect put the last one don't work, I trying different thing but still...

  • #13
    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
    Quote Originally Posted by Peuplarchie View Post
    it dont work
    Can you clarify what didn't work? I didn't test the code out, is it syntactical or is it logical?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #14
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post
    nothing appears in the selection box.

  • #15
    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
    Are you still running the loop to generate the options?
    PHP Code:
    for ($i 0$i count($colourArray); $i++)
    {
        
    $selected = ($colourArray[$i][1] == trim($_POST['COLOUR_CHOICE'])) ? 'selected="selected"' '';
        echo 
    '<option value="' $colourArray[$i][1] . '"' $selected '>' $colourArray[$i][0] . '</option>'

    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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