Jump to content

Clear Old Table Data


shobhit.singh783
 Share

Recommended Posts

Hi,I wrote html file using html and java script and css. When i open this html file in browser and select option from drop down then it shows table data but when i try other options after that new data appears on browser and old data also appear and I want only new data on browser corresponding to option selected from drop down. Please tell me the method to clear old data.

<html><head><link rel="stylesheet" href="in.css"><script src="json.js"></script><script type="text/javascript">function writebox(form){if(form.campaigns.value=="1"){var j = 0;var count = form.campaigns.selectedIndex;//document.write(count);var rowCount = campaignData[count].row.length;// creating all cellsfor (j = 0; j <rowCount; j++) {var x = document.getElementById('mtb').insertRow(j+1);var a=x.insertCell(0);var b=x.insertCell(1);var c=x.insertCell(2);var d=x.insertCell(3);var e=x.insertCell(4);var f=x.insertCell(5);a.innerHTML='<a id="k" href="java script: detail1(this.innerHTML)" onClick="detail1(this.innerHTML)">'+campaignData[count].row[j].name+'</a>' ;b.innerHTML=campaignData[form.campaigns.selectedIndex].row[j].total;c.innerHTML=campaignData[form.campaigns.selectedIndex].row[j].accepted;d.innerHTML=campaignData[form.campaigns.selectedIndex].row[j].rejected;e.innerHTML=campaignData[form.campaigns.selectedIndex].row[j].duplicates;f.innerHTML=campaignData[form.campaigns.selectedIndex].row[j].invalids;}}else if(form.campaigns.value=="2"){var j = 0;var count = form.campaigns.selectedIndex;//document.write(count);var rowCount = campaignData[count].row.length;// creating all cellsfor (j = 0; j <rowCount; j++) {var x = document.getElementById('mtb').insertRow(j+1);var a=x.insertCell(0);var b=x.insertCell(1);var c=x.insertCell(2);var d=x.insertCell(3);var e=x.insertCell(4);var f=x.insertCell(5);a.innerHTML= '<a href="destination.html">'+campaignData[count].row[j].name+'</a>' ;b.innerHTML=campaignData[form.campaigns.selectedIndex].row[j].total;c.innerHTML=campaignData[form.campaigns.selectedIndex].row[j].accepted;d.innerHTML=campaignData[form.campaigns.selectedIndex].row[j].rejected;e.innerHTML=campaignData[form.campaigns.selectedIndex].row[j].duplicates;f.innerHTML=campaignData[form.campaigns.selectedIndex].row[j].invalids;}}else if(form.campaigns.value=="3"){var j = 0;var count = form.campaigns.selectedIndex;var rowCount = campaignData[count].row.length;// creating all cellsfor (j = 0; j <rowCount; j++) {var x = document.getElementById('mtb').insertRow(j+1);var a=x.insertCell(0);var b=x.insertCell(1);var c=x.insertCell(2);var d=x.insertCell(3);var e=x.insertCell(4);var f=x.insertCell(5);a.innerHTML='<a href="destination.html">'+campaignData[count].row[j].name+'</a>' ;b.innerHTML=campaignData[form.campaigns.selectedIndex].row[j].total;c.innerHTML=campaignData[form.campaigns.selectedIndex].row[j].accepted;d.innerHTML=campaignData[form.campaigns.selectedIndex].row[j].rejected;e.innerHTML=campaignData[form.campaigns.selectedIndex].row[j].duplicates;f.innerHTML=campaignData[form.campaigns.selectedIndex].row[j].invalids;}}}</script><script TYPE="text/javascript">function detail1(txt){if(txt=='Partner One'){my_window = window.open("",    "mywindow","status=1,width=350,height=150");my_window.document.write(txt+"\r\n"+campaignData[0].row[0].total+"\r\n"+campaignData[0].row[0].accepted+"\r\n"+campaignData[0].row[0].rejected+"\r\n"+campaignData[0].row[0].duplicates+"\r\n"+campaignData[0].row[0].invalids);my_window.document.write('<A href="java script: self.close()">close popup</A>');}else if(txt=='Partner Two'){my_window = window.open("",    "mywindow","status=1,width=350,height=150");my_window.document.write(txt+"\r\n"+campaignData[0].row[0].total+"\r\n"+campaignData[0].row[0].accepted+"\r\n"+campaignData[0].row[0].rejected+"\r\n"+campaignData[0].row[0].duplicates+"\r\n"+campaignData[0].row[0].invalids);my_window.document.write('<A href="java script: self.close()">close popup</A>');}else if(txt=='Partner Three'){my_window = window.open("",    "mywindow","status=1,width=350,height=150");my_window.document.write(txt+"\r\n"+campaignData[0].row[0].total+"\r\n"+campaignData[0].row[0].accepted+"\r\n"+campaignData[0].row[0].rejected+"\r\n"+campaignData[0].row[0].duplicates+"\r\n"+campaignData[0].row[0].invalids);my_window.document.write('<A href="java script: self.close()">close popup</A>');}else if(txt=='Partner Four'){my_window = window.open("",    "mywindow","status=1,width=350,height=150");my_window.document.write(txt+"\r\n"+campaignData[0].row[0].total+"\r\n"+campaignData[0].row[0].accepted+"\r\n"+campaignData[0].row[0].rejected+"\r\n"+campaignData[0].row[0].duplicates+"\r\n"+campaignData[0].row[0].invalids);my_window.document.write('<A href="java script: self.close()">close popup</A>');}}</SCRIPT><script TYPE="text/javascript">function detail2(){var option = 2;document.write("hello "+option);}</SCRIPT><script TYPE="text/javascript">function detail3(){var option = 3;document.write("hello "+option);}</SCRIPT><script TYPE="text/javascript">function popuponclick(txt){ my_window = window.open("",    "mywindow","status=1,width=350,height=150");my_window.document.write('<H1>'+txt+'</H1>');my_window.document.write('<A href="java script: self.close()">close popup</A>');}</SCRIPT></head><body><h1>Nick's Famous Muffins</h1><form action="">Select Campaign:<select name="campaigns" onchange='writebox(this.form);'>	<!--<option value="none" selected></option>-->	<option value="1" selected>Campaign Report One</option>	<option value="2">Campaign Report Two</option>	<option value="3">Campaign Report Three</option></select><br><br><table id="mtb" width="50%" border="1" cellpadding="1" >	<tr>		<td id="name">Partner Name</td>		<td>Total Received</td>		<td>Accepted</td>		<td>Rejected</td>		<td>Duplicates</td>		<td>Invalids</td>	</tr>	<tr>		<td><a href="popup.html" onClick="return popup(this, 'notes')"><span id="thebox1"></span></a></td>		<td><span id="thebox2"></span></td>		<td><span id="thebox3"></span></td>		<td><span id="thebox4"></span></td>		<td><span id="thebox5"></span></td>		<td><span id="thebox6"></span></td>	</tr></table></form></body></html>

Link to comment
Share on other sites

Add these lines near the top of your writebox() function. I assume you don't want to delete the 2 rows that the table has when the page first loads, so I created a way to keep some rows. If you need to change the number of rows you keep, then just change the keepers variable to another value.

var keepers = 2; // HOWEVER MANY ROWS YOU NEED TO KEEPvar tbl = document.getElementById('mtb');while (tbl.rows.length > keepers) {	document.getElementById('myTable').deleteRow(keepers);}

Link to comment
Share on other sites

Thanks it works fine

Add these lines near the top of your writebox() function. I assume you don't want to delete the 2 rows that the table has when the page first loads, so I created a way to keep some rows. If you need to change the number of rows you keep, then just change the keepers variable to another value.
var keepers = 2; // HOWEVER MANY ROWS YOU NEED TO KEEPvar tbl = document.getElementById('mtb');while (tbl.rows.length > keepers) {	document.getElementById('myTable').deleteRow(keepers);}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...