I got this table with a built in calculator function that select from different parts of the table
and adds every thing up at the end. But my problem is that if I hit one of the squares with letters inside of them instead of numbers, the calculator breaks, how do I fix it?
How do I make the first like containing information(car names) unclickable, and only the first 5 squares. The table code :
<table>
<tr>
<th bgcolor="b8cce4">Modell</td>
<th>Trend</td>
<th>Titanum</td>
<th>Familiepakke</td>
<th>Førerassistentpakke</td>
<th>Stilpakke</td>
<th>Sluttpris</td>
</tr>
<tr>
<td bgcolor="b8cce4"><b>Kuga</b></td>
<td>401000</td>
<td>420000</td>
<td>1000</td>
<td>10200</td>
<td>9200</td>
<td>kr</td>
</tr>
<tr>
<td bgcolor="b8cce4"><b>C-max</b></td>
<td>320000</td>
<td>335000</td>
<td>1000</td>
<td>9400</td>
<td>3600</td>
<td>kr</td>
</tr>
<tr>
<td bgcolor="b8cce4"><b>Focus</b></td>
<td>255000</td>
<td>325000</td>
<td>900</td>
<td>12500</td>
<td>9000</td>
<td>kr</td>
</tr>
<tr>
<td bgcolor="b8cce4"><b>Mondeo</b></td>
<td>281000</td>
<td>361000</td>
<td>1100</td>
<td>9900</td>
<td>7200</td>
<td>kr</td>
</tr>
The script:
(function() {
var tds = document.querySelectorAll('tr td:not(:last-child)');
for (var td in tds) {
tds[td].addEventListener('click', function(evt) {
evt.target.classList.toggle('selected');
var total = 0;
var parentTr = evt.target.parentNode;
var selected = parentTr.querySelectorAll('.selected');
for (var k in selected) {
if (selected[k].innerText) {
total += parseInt(selected[k].innerText);
}
}
parentTr.querySelector('td:last-child').innerText = total;
});
}
})();