I currently have several if statements that populate a specific table after the button refresh has been clicked.
After the button is clicked again I need to remove the previous table that is polulated. How can I do that?
if (strDate == "Jan-2010") {
var TableRowHtml = "<table id='box-table-a'>";
TableRowHtml +="<TR><TH 'style='width: 50px'>OPERATIONS</TH></TR>";
TableRowHtml +="<TR><TH 'style='width: 50px'>Unit Costs</TH></TR>";
TableRowHtml +="<TR><TD>" + Total[0] + "</TD></TR>";
}
else if (strDate == "Feb-2010") {
var TableRowHtml1 = "<table id='box-table-a'>";
TableRowHtml1 +="<TR><TH 'style='width: 50px'>OPERATIONS</TH></TR>";
TableRowHtml1 +="<TR><TH 'style='width: 50px'>Unit Costs</TH></TR>";
TableRowHtml1 +="<TR><TD>" + Total[1] + "</TD></TR>";
}
else if (strDate == "Mar-2010") {
var TableRowHtml2 = "<table id='box-table-a'>";
TableRowHtml2 +="<TR><TH 'style='width: 50px'>OPERATIONS</TH></TR>";
TableRowHtml2 +="<TR><TH 'style='width: 50px'>Unit Costs</TH></TR>";
TableRowHtml2 +="<TR><TD>" + Total[2] + "</TD></TR>";
}
else if (strDate == "Apr-2010") {
var TableRowHtml3 = "<table id='box-table-a'>";
TableRowHtml3 +="<TR><TH 'style='width: 50px'>OPERATIONS</TH></TR>";
TableRowHtml3 +="<TR><TH 'style='width: 50px'>Unit Costs</TH></TR>";
TableRowHtml3 +="<TR><TD>" + Total[3] + "</TD></TR>";
}
Dropdown code:
<tr><td><select id="combobox">
<option value="Jan-2010">Jan/2010</option>
<option value="Feb-2010">Feb/2010</option>
<option value="Mar-2010">Mar/2010</option>
<option value="Apr-2010">Apr/2010</option>
<option value="May-2010">May/2010</option>
<option value="Jun-2010">Jun/2010</option>
</select></td>
<td><input type="button" id="RefreshMetrics" value="Refresh"></td>
</tr>
</select></td>
<td><input type="button" id="RefreshMetrics" value="Refresh"></td>
</tr>
</table>
/////////////////////////////////////////////////////////////////////////////
Can place the below code in each specfic if statement e.g… remove each table that is not needed … for that paticular month
if (strDate == "Jan-2010")
{
$('TableRowHtml1').last().remove();
$('TableRowHtml2').last().remove();
$('TableRowHtml3').last().remove();
var TableRowHtml = "<table id='box-table-a'>";
TableRowHtml +="<TR><TH 'style='width: 50px'>OPERATIONS</TH></TR>";
TableRowHtml +="<TR><TH 'style='width: 50px'>Unit Costs</TH></TR>"; TableRowHtml +="<TR><TD>" + Total[0] + "</TD></TR>";
}
You can use Jquery remove API.
http://api.jquery.com/remove/
$('table').last().remove();