Show Hide Multiple rows using same ID

Ive a table which displays some history of an user and that is displayed in different rows. So the structure is something like this :

- Member Name
-- History1
-- History 2

Basically the number of "History" rows is determined by the database since its dynamically created. There would be named like "name1", "name2", "name3"...and so on. So i need a way to show/hide these rows based on the name i pass. For instance if i pass "mark" to the javascript function, it should show/hide all rows that use "mark" in their id. See code example below for reference.

<table border="0" cellpadding="2" cellspacing="2">
  <tr>
    <td bgcolor="#D6C899" class="borderbrowndotted"><strong><a href="#" onCLick="showhide('mark')">Name</a></strong></td>
    <td bgcolor="#F4E9C4" class="borderbrown">&nbsp;</td>
    <td bgcolor="#F4E9C4" class="borderbrown">&nbsp;</td>
    <td bgcolor="#F4E9C4" class="borderbrown">&nbsp;</td>
  </tr>
  <tr id="mark1" style="display:none">
    <td bgcolor="#CCCCCC" class="borderbrowndotted">15/1/2005</td>
    <td bgcolor="#FAF2D7" class="borderbrown">a</td>
    <td bgcolor="#FAF2D7" class="borderbrown">a</td>
    <td bgcolor="#FAF2D7" class="borderbrown">a</td>
  </tr>
  <tr id="mark2" style="display:none">
    <td bgcolor="#CCCCCC" class="borderbrowndotted">15/1/2005</td>
    <td bgcolor="#FAF2D7" class="borderbrown">b</td>
    <td bgcolor="#FAF2D7" class="borderbrown">b</td>
    <td bgcolor="#FAF2D7" class="borderbrown">b</td>
  </tr>
</table>
inexplicableAsked:
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.

GwynforWebCommented:
try tihis

<script>
function showhide(key){
 theRows=document.getElementById("dataTable").rows
 reg=new RegExp("^"+key)
 for (i=0;i<theRows.length;i++)
  if (reg.test(theRows[i].id))
     if  (theRows[i].style.display=="none")
       theRows[i].style.display=""
       else
       theRows[i].style.display="none"  
}

</script>

<table border="0" cellpadding="2" cellspacing="2" id="dataTable">
  <tr>
    <td bgcolor="#D6C899" class="borderbrowndotted"><strong><a href="#"
    onCLick="showhide('mark')">Name</a></strong></td>
    <td bgcolor="#F4E9C4" class="borderbrown">a</td>
    <td bgcolor="#F4E9C4" class="borderbrown">a</td>
    <td bgcolor="#F4E9C4" class="borderbrown">a</td>
  </tr>
  <tr id="mark1" style="display:none">
    <td bgcolor="#CCCCCC" class="borderbrowndotted">15/1/2005</td>
    <td bgcolor="#FAF2D7" class="borderbrown">a</td>
    <td bgcolor="#FAF2D7" class="borderbrown">a</td>
    <td bgcolor="#FAF2D7" class="borderbrown">a</td>
  </tr>
  <tr id="mark2" style="display:none">
    <td bgcolor="#CCCCCC" class="borderbrowndotted">15/1/2005</td>
    <td bgcolor="#FAF2D7" class="borderbrown">b</td>
    <td bgcolor="#FAF2D7" class="borderbrown">b</td>
    <td bgcolor="#FAF2D7" class="borderbrown">b</td>
  </tr>
  <tr id="markFinal " style="display:none">
    <td bgcolor="#CCCCCC" class="borderbrowndotted">15/1/2005</td>
    <td bgcolor="#FAF2D7" class="borderbrown">b</td>
    <td bgcolor="#FAF2D7" class="borderbrown">b</td>
    <td bgcolor="#FAF2D7" class="borderbrown">b</td>
  </tr>
</table>

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
inexplicableAuthor Commented:
Doesnt work. It gives error for some reason "Object required"
GwynforWebCommented:
I have just retested the above code in IE and FireFox and it works for me
GwynforWebCommented:
..make sure the table has an id
inexplicableAuthor Commented:
Excellent works fine now. My bad!
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
JavaScript

From novice to tech pro — start learning today.