Forum Moderators: open

Message Too Old, No Replies

changing table(generated at runtime with loop) color

HTML , ASP, Javascript

         

hazee

3:36 pm on Apr 25, 2008 (gmt 0)

10+ Year Member



Code:

<html>
<script type="text/javascript">
function check(x)
{
document.getElementById("myTable").bgColor=x
}
</script>
<body>
<%
rs.CursorType = 2
rs.LockType = 3
rs.Open "SELECT * FROM tbl_students", adocon
do while rs.EOF=false
%>
<table id="myTable" width="200" border="1">
<tr>
<td><%=rs.fields(0)%></td>
</tr>
<tr>
<td><input type="checkbox" name="asd" onclick="check(this.value)" value="blue">Select to Print</td>
</tr>
</table>
<%rs.movenext
loop%>
</body>
</html>

This loop will generate as many tables as the number of records filtered by recordset object. If i click any checkbox it changes the background color of the first table generated by loop.

What I want is, that it should change the color of corresponding table. FOr example 3 records filtered, so 3 tables generated. If I click the checkbox in 3rd table, it should only change the color of 3rd table not first.

Response

5:30 pm on Apr 25, 2008 (gmt 0)

10+ Year Member



Hazee,

You will need a unique ID for each table (MyTable). Try rs.AbsolutePosition or a counter to add to the ID string ("MyTable" & counter). Output the same string for the onclick event of the checkbox.

Unless the 'blue' color of the value is changing from table to table, I would recommend switching the CSS class of the Table in your click function. As opposed to passing it to the function.

-Response

hazee

6:50 pm on Apr 25, 2008 (gmt 0)

10+ Year Member



Good idea ... It worked.