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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Highlight most recent record 1

Status
Not open for further replies.

apex82

Programmer
Mar 2, 2009
127
GB
I'm displaying records from a database:
Code:
While Not obj_RS1.EOF
	Response.Write "<tr>"
        Response.Write "<td>" & obj_RS("Make") & "</td>"
        Response.Write "<td>" & obj_RS("Model") & "</td>"
	Response.Write "<td>" & obj_RS("Delivery Date") & "</td>"
	Response.Write "<td>" & obj_RS("Reg")  & "</td>"
        Response.Write "</tr>"
obj_RS.MoveNext

When they are listed on my page I want to highlight the most recent record which would on the most recent date.
Maybe highlight with the <td> background a different color?

Does anyone know how I could do this?

I've been searching for examples and trying this myself but not had any success.

Thanks.
 
Create a counter and give each row an ID

Code:
<tr "row_<%=counter%>">
<td>...</td>
<td>...</td>
</tr>

Put that counter within the loop and increment it each time
Code:
counter = 0
while not ojb_RS1.eof
counter = counter + 1
...
loop

Keep track of the dates and if the date of the current record is greater than the previous record, set a variable to the value of the counter.

Code:
intLatestDate = counter

At the very end of your page, above the body tag add this:

Code:
<script language="javascript">
document.getElementById("row_<%=intLatestDate%>").style.background = "#cccccc";
</script>

TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
Brilliant! Thanks vicvirk.

I just can't find a way to add:

Code:
<tr "row_<%=counter%>">

after Response.Write
 
Code:
Response.Write "<tr id=""row_" & counter & "">"
or
Response.Write "<tr id='row_" & counter & "'>"

Haven't tested it, but the first one may have too many/not enough quotes...



TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
Second one worked just great!

Thanks very much!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top