Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete a dynamic table

Status
Not open for further replies.

deeciple

Technical User
Mar 1, 2012
70
US
Hi All,

I hate to ask such a basi question but is there any function or method to delete an html table? I have tried destroy(), removeChild() with no luck. I created a function that dynamically creates a table and adds rows to it. The code is called via a checkbox. I would like, if the user changes their mind and uchecks the box I would like the table to be deleted so that the data will not post to my database. This is what I have to delete but it's not working:

JavaScript:
   //if exists table entries for the div, delete them
if (dynaTable = document.getElementById("dataTable")) {
dynaTable.destroy();
}

Thanks,

Ken
 
Try: mdynaTable.style.visibility='none';
I'm pretty sure that any child input elements will not populate the form object on your action page...

Then you could restore the table state if the client toggles the checkbox using: mdynaTable.style.visibility='block';


Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
removeChild() is the correct method to employ. Though it must be used from the parent of the element you wish to remove.

Code:
dynaTable.parentNode.removeChild(dynaTable);



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Thanks all. I will try these out and post back soon. [bigsmile]

Kind regards,

Ken
 
Vacunita,

Thanks, I wasn't aware of the proper usage of this method. Once I added the parentNode element it worked. It would have been great to be able to provide the flexibility that Lyndon suggested but I couldn't get that to work.

Thanks all,

Ken
 
Glad It worked. As for Lyndon's code, its probably because the Visibility property does not have a block value, rather hidden, visible, collapsed¿ (for tables only) or inherit.

[link]http://www.w3schools.com/cssref/pr_class_visibility.asp[/url]

Though I'm not sure if that will prevent submission of the fields within.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top