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 8 of 8
  1. #1
    Regular Coder
    Join Date
    Sep 2002
    Location
    Bugaha, NE
    Posts
    330
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Shade row in a select box?

    Hi.

    I need to be able to shade the row of a select box depending on the value of it. If it matches a certain criteria, it should be gray, or whatever.

    Can I do this?
    This is in spanish when you're not looking.

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    New York, USA
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sure you can script that after checking your criteria like:

    document.formname.selectname.options[someoption].style.backgroundColor = 'somecolor';

  • #3
    Regular Coder
    Join Date
    Sep 2002
    Location
    Bugaha, NE
    Posts
    330
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That answers my question. I should be able to rig it up from there.

    Many thanks.
    This is in spanish when you're not looking.

  • #4
    Regular Coder
    Join Date
    Sep 2002
    Location
    Bugaha, NE
    Posts
    330
    Thanks
    0
    Thanked 0 Times in 0 Posts
    In this example given, what takes the place of

    option[someoption] ?

    What I'm doing is pulling a list of data from a database, using ASP, I'm writing an <option> for each row in the recordset.

    If the row has and expiration_date, I want to use javascript to set the background color of that <option> to a different color.

    So far my code looks like:

    <option value = "MyValue"

    <%

    IF ExpDate <> "" then response.write "document.tpainfo.tpa.options[someoption].style.backgroundColor = 'red';" end if %>>
    MyValue
    </option>
    This is in spanish when you're not looking.

  • #5
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you're writing with ASP, why not just add a class to the option, then define that class in your CSS. That way, if you want to change how the highlight looks, just open your CSS and leave the ASP alone
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #6
    Regular Coder
    Join Date
    Sep 2002
    Location
    Bugaha, NE
    Posts
    330
    Thanks
    0
    Thanked 0 Times in 0 Posts
    How would I do that? I'm having a hard time getting the syntax for that.
    This is in spanish when you're not looking.

  • #7
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, I don't know ASP (vbscript) but I can show you what it would look like in PHP
    PHP Code:
    if ( $ExpDate != "" )
        echo ( 
    '<option value="$value" class="highlight">$text</option>' );
    else
        echo ( 
    '<option value="$value">$text</option>' ); 
    Then, in the CSS
    Code:
    option.highlight {
        background-color: red;
        }
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #8
    Regular Coder
    Join Date
    Sep 2002
    Location
    Bugaha, NE
    Posts
    330
    Thanks
    0
    Thanked 0 Times in 0 Posts


    Nifterooni!


    It worked. That little bit of php is easy enough to understand to translate to ASP. Besides, all I needed was the style info.

    Many, many thanks.
    This is in spanish when you're not looking.


  •  

    Posting Permissions

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