Toggle row with javascript in asp

The following code should toggle an additional row for each record.  However it only toggles the first row.  If I check the checkbox on any record, the first record toggles only.

   <script language="JavaScript">

    function toggle(target)
     {
         obj=document.getElementById(target);
         obj.style.display=( (obj.style.display=='none') ? '' : 'none');
     }
    </script>

<input style="display:inline" type="checkbox" onClick="toggle('therow')" id=checkbox1 name=checkbox1>

      <tr  id="therow" style="display:none" bgcolor="<%= bgcolor %>">
<td colspan="9"><span class="aspmaker"><%=SubjectLine%></span>&nbsp;</td>

      </tr>

<%
      End If
      rs.MoveNext
Loop
%>
LVL 3
Insomniac_PhDAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
sajuksConnect With a Mentor Commented:
You have to generate your tr id  dynamically. You are referencing the row as therow. But when you have multiople rows
the name for each row has to be distinct. like
     <tr  id="therow" style="display:none" bgcolor="<%= bgcolor %>"> </tr>
     <tr  id="therow1" style="display:none" bgcolor="<%= bgcolor %>"></tr>
     <tr  id="therow2" style="display:none" bgcolor="<%= bgcolor %>"></tr>.
As of now you are just calling toggle('therow') which will fire only for the first row
Also i presume the checkbox will be on each row ?

0
 
Insomniac_PhDAuthor Commented:
yes. the checkbox is on the row above in each record.
0
 
sajuksCommented:
Your checkboxes should look like this
<input style="display:inline" type="checkbox" onClick="toggle('therow')" id=checkbox1 name=checkbox1>
<input style="display:inline" type="checkbox" onClick="toggle('therow1')" id=checkbox1 name=checkbox1>
<input style="display:inline" type="checkbox" onClick="toggle('therow2')" id=checkbox1 name=checkbox1>
Since you will be dynamically creating the table row id <tr id = "throw"+i>
you just need to pass the same dynamic value  to onClick="toggle("
0
 
Insomniac_PhDAuthor Commented:
Got it!  I just used the record key as the dynamic reference.

Thanks.
0
 
sajuksCommented:
Thanks for the points and grade
0
All Courses

From novice to tech pro — start learning today.