Multiple colors on <select> list

Discussion in 'ASP General' started by PW, May 30, 2006.

  1. PW

    PW Guest

    Is it possible to make a select list item red based on a condition ?

    TIA,
    PW
     
    PW, May 30, 2006
    #1
    1. Advertising

  2. PW

    Mike Brind Guest

    PW wrote:
    > Is it possible to make a select list item red based on a condition ?
    >
    > TIA,
    > PW


    Are you asking whether one can apply different styles to items in a
    select list, or how to code conditional statements with server-side
    code?

    If the first, try googling optgroup and css, and see if this answers
    your question. If it doesn't, you would be better off asking in a css
    or stylesheet group.

    If it's the second (although I suspect not) show the code you've tried,
    and explain where it fails.

    --
    Mike Brind
     
    Mike Brind, May 30, 2006
    #2
    1. Advertising

  3. PW

    PW Guest

    "Mike Brind" <> wrote in message
    news:...
    >
    > PW wrote:
    >> Is it possible to make a select list item red based on a condition ?
    >>
    >> TIA,
    >> PW

    >
    > Are you asking whether one can apply different styles to items in a
    > select list, or how to code conditional statements with server-side
    > code?
    >
    > If the first, try googling optgroup and css, and see if this answers
    > your question. If it doesn't, you would be better off asking in a css
    > or stylesheet group.
    >
    > If it's the second (although I suspect not) show the code you've tried,
    > and explain where it fails.
    >
    > --
    > Mike Brind
    >


    Hi Mike,

    Thanks for your response. I have since googled and found an answer.

    I've created the css as suggested ...

    <head>
    <STYLE type="text/css">
    OPTION.red{background-color:white; color:red}
    OPTION.black{background-color:white; color:black}
    </STYLE>
    </head>

    I then created a string based on the condition ...

    if len(rs1("NOTES")) > 0 then
    myOptionText = " class=red "
    else
    myOptionText = " class=black "
    end if

    And then concatenated the string into the <option> statement based on the
    condition ...

    if mySearchString <> "" then
    if rs1("ESCI") = mySearchString then
    response.write "<option selected " & myOptionText & ">"
    else
    response.write "<option " & myOptionText & ">"
    end if
    elseif rs1("ESCI") = left(myQueryString,6) then
    response.write "<option selected " & myOptionText & ">"
    else
    response.write "<option " & myOptionText & ">"
    end if


    Thanks,
    PW
     
    PW, May 31, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. AAaron123

    TreeNode colors come from anchor colors

    AAaron123, Aug 7, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    564
    darrel
    Aug 7, 2008
  2. ZelluX
    Replies:
    3
    Views:
    1,962
    Peter Otten
    Dec 1, 2008
  3. palmiere
    Replies:
    1
    Views:
    471
    Erwin Moller
    Feb 9, 2004
  4. Ferd Berfel
    Replies:
    4
    Views:
    169
  5. Amy
    Replies:
    4
    Views:
    171
Loading...

Share This Page