...

View Full Version : Shade row in a select box?



BigDaddy
04-03-2003, 04:15 PM
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?

boywonder
04-03-2003, 05:06 PM
sure you can script that after checking your criteria like:

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

BigDaddy
04-03-2003, 10:10 PM
That answers my question. I should be able to rig it up from there.

Many thanks. :thumbsup:

BigDaddy
04-04-2003, 04:47 PM
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>

beetle
04-04-2003, 05:19 PM
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 :D

BigDaddy
04-04-2003, 05:20 PM
How would I do that? I'm having a hard time getting the syntax for that.

beetle
04-04-2003, 05:27 PM
Well, I don't know ASP (vbscript) but I can show you what it would look like in PHP
if ( $ExpDate != "" )
echo ( '<option value="$value" class="highlight">$text</option>' );
else
echo ( '<option value="$value">$text</option>' );
Then, in the CSS
option.highlight {
background-color: red;
}

BigDaddy
04-04-2003, 05:31 PM
:thumbsup: :thumbsup: :thumbsup:

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. :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum