Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

remove all rows from a table

Posted on 2006-04-14
2
Medium Priority
?
8,530 Views
Last Modified: 2010-05-18
Hi,

I got a HTML table script that lets you add and delete a row at a time. Is there a quick way to just delete ALL rows in the table at once? (I dont want to go call deleteRow() dozens of times to clear it if possible)

Thanks
0
Comment
Question by:minnirok
2 Comments
 
LVL 6

Accepted Solution

by:
nabsol earned 1000 total points
ID: 16458086
Hi

Hope it helps.

<HTML><HEAD><TITLE>Test</TITLE>
<script language="JavaScript">
function deleteall(mytable)
{
   for(i=mytable.rows.length-1; i > -1; i--)
       mytable.deleteRow(i);
}
</script>

<BODY>

<table border="1" id="mytable">
<tr><td>first column</td><td>second</td>
<tr><td>first column</td><td>second</td>
<tr><td>first column</td><td>second</td>
<tr><td>first column</td><td>second</td>
</table>

<input type="button" onclick="deleteall(mytable)" value = "delete all">
</BODY></HTML>

By Nab
0
 
LVL 7

Author Comment

by:minnirok
ID: 16458180
Hi Nab,

That works, thanks - I have another question on list stuff which I'll post in a minute if you want to take a look,

Thanks
0

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

810 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