Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change Text color based on Results

Status
Not open for further replies.

schase

Technical User
Sep 7, 2001
1,756
US
Having database pull a value from the table, would like the results to be color coded based on what the field is. The fields are also repeat region

<% If (Recordset1.Fields.Item(&quot;pilot_status&quot;).Value) = &quot;Online&quot; Then%><td width=&quot;50&quot; color=&quot;#33FF00&quot;><% Else %><td width=&quot;50&quot; color=&quot;#FFCC66&quot;><% End If %>

for some reason UD4 removes all but:
<%=If(Recordset1.Fields.Item(&quot;pilot_status&quot;).Value)= &quot;Online&quot;%>

Also get this error:

Microsoft VBScript compilation error '800a03ea'

Syntax error

/db/test.asp, line 49

Response.Write(If(Recordset1.Fields.Item(&quot;pilot_status&quot;).Value)= &quot;Online&quot;)

Any ideas? I am looking to change just the font color based on results.

Thank you in advance

 
UD is removing that for you because the attribute to change the background color of your cell is

bgcolor, instead of color, so:

<% If (Recordset1.Fields.Item(&quot;pilot_status&quot;).Value) = &quot;Online&quot; Then%><td width=&quot;50&quot; bgcolor=&quot;#33FF00&quot;><% Else %><td width=&quot;50&quot; bgcolor=&quot;#FFCC66&quot;><% End If %>

and for your syntax error, it's probably expecting a &quot;then&quot; in your response.write(), since you put an &quot;if&quot; in there.

If you just want to see the value of the field, then try this:

Response.Write(Recordset1.Fields.Item(&quot;pilot_status&quot;).Value)

:)
paul
penny.gif
penny.gif
 
Shouldn't be a problem. There's some contradiction, though. Which line are you actually using:

[red]<% If (Recordset1.Fields.Item(&quot;pilot_status&quot;).Value) = &quot;Online&quot; Then%>[/red]

or

<%= If (Recordset1.Fields.Item(&quot;pilot_status&quot;).Value) = &quot;Online&quot; Then%>

?
I'm asking that because the red one is the on that performs the condition check, while the blue one writes (it is the equivalent of Response.Write) whatever behind the = sign to the browser.
You should stick with the red line. And use another form of getting the field value:

[red]<% If Recordset1(&quot;pilot_status&quot;) = &quot;Online&quot; Then%>[/red]

Saves you some typing.
 
Thank you Link, but I do not want to change the background color, I want to change the font color. I tried to manipulate a bgcolor change into a font color change.
 
Ah. I see.

Well, still, that's why UD is getting rid of the tag. It's bad about cleaning up HTML for you automatically.

So, then all you need is:

<td width=50>
<%
If (Recordset1.Fields.Item(&quot;pilot_status&quot;).Value) = &quot;Online&quot; Then
response.write(&quot;<font color=#33FF00>&quot;)
Else
response.write(&quot;<font color=#FFCC66>&quot;)
End If
%>

that should fix you up.
penny.gif
penny.gif
 
Getting closer I think, but it isn't placing the value from the table into the table field. - the table does have a value, I have two records for testing that should show, one with Online the other says offline.

<td bgcolor=&quot;#000000&quot; width=&quot;50&quot; >
<%
If (Recordset1.Fields.Item(&quot;pilot_status&quot;).Value) = &quot;Online&quot; Then
response.write(&quot;<font color=#33FF00>&quot;)
Else
response.write(&quot;<font color=#FFCC66>&quot;)
End If
%>
</TD>

I've tried putting pilot_status right after the font color tag with no quotes, single and double with no success.
 
well, you'll still need to response.write() the value in there. full code solution would look like this:

<td bgcolor=&quot;#000000&quot; width=&quot;50&quot; >
<%
If (Recordset1.Fields.Item(&quot;pilot_status&quot;).Value) = &quot;Online&quot; Then
response.write(&quot;<font color=#33FF00>&quot;)
Else
response.write(&quot;<font color=#FFCC66>&quot;)
End If
response.write(Recordset1.Fields.Item(&quot;pilot_status&quot;).Value)
%>
</font>
</TD>
penny.gif
penny.gif
 
ahhh gottchya,

Ok, I figured the response.write would do the color and the value.

Works perfect

Thank you!

p.s. Thank you for responding also GuestG, I had actually skipped over your post by accident - then just continued with one solution.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top