Link to home
Start Free TrialLog in
Avatar of Insomniac_PhD
Insomniac_PhD

asked on

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
%>
ASKER CERTIFIED SOLUTION
Avatar of sajuks
sajuks

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Insomniac_PhD
Insomniac_PhD

ASKER

yes. the checkbox is on the row above in each record.
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("
Got it!  I just used the record key as the dynamic reference.

Thanks.
Thanks for the points and grade