Results 1 to 6 of 6

Thread: changing table (generated with loop) color

  1. #1
    Join Date
    Apr 2008
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Red face changing table (generated with loop) color

    This is HTML, Javascript and ASP
    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.

  2. #2
    Join Date
    Feb 2008
    Location
    Buenos Aires, Argentina
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Hmmm...

    Try placing:

    this.style.backgroundColor='Red'

    in the onClick

  3. #3
    Join Date
    Apr 2008
    Posts
    1
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    Part of your problem is 'myTable' is the id for all three tables. You should set a 'RecCount=0' just before the 'Do While' and add a counter (i.e. - RecCount = RecCount + 1) right before the 'Loop' and set the table id's to 'id="myTable_<%= RecCount %>"'.

    Now, you have distinct id's and can run your javascript function. You just need to modify the function to accept the number of the id you are wanting to change...
    Code:
    <script type="text/javascript">
    function check(x, WhichTable)
    {
    document.getElementById(WhichTable).backgroundColor=x
    }
    </script>
    ... to call it...

    Code:
    onclick="check(this.value, 'myTable_<%= RecCount %>')"
    To use the simpler 'onclick' code from dsagrera, you would need to still have distinct table id's and the 'onclick' should be...
    Code:
    onclick="myTable_<%= RecCount %>.style.backgroundColor='blue';"
    ...or...
    Code:
    onclick="myTable_<%= RecCount %>.style.backgroundColor=this.value;"

  4. The Following User Says Thank You to ooosadface For This Useful Post:

    hazee (05-19-2008)

  5. #4
    Join Date
    May 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Red face Like you to write articles

    Like you to write articles, SEOfor you Come on! !

  6. #5
    Join Date
    May 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default nice

    Nice topic, nice article.

  7. #6
    Join Date
    Apr 2008
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thanks ... a big help.

    Going to post another thread. Hopefully someone can answer.

Bookmarks

Posting Permissions

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