[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now


Toggle row with javascript in asp

Posted on 2004-10-29
Medium Priority
Last Modified: 2012-06-27
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.style.display=( (obj.style.display=='none') ? '' : 'none');

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


      End If
Question by:Insomniac_PhD
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 33

Accepted Solution

sajuks earned 1200 total points
ID: 12450368
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 ?


Author Comment

ID: 12450418
yes. the checkbox is on the row above in each record.
LVL 33

Expert Comment

ID: 12450434
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("

Author Comment

ID: 12450441
Got it!  I just used the record key as the dynamic reference.

LVL 33

Expert Comment

ID: 12450444
Thanks for the points and grade

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question