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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sajuksCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.