PDA

View Full Version : Remove/Modify specified th and td


DoubleJ
06-20-2007, 04:59 PM
Eh I'm new to DOM concept and this issue's kind of beyond my knowledge, so hope somebody could lend a hand on it:

I'm using a fantasy football third party software to populate a table (id=roster) contents that resides in a specified page that I need a script to work only for (other page use this table too but don't need script to do it):

bascially the third party software populates the roster table structure something like this:

<body id="home">
<table id="roster">
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
continue to populate more tds depend on how many infomation are stored in db
<tr>
<th colspan="7"></th>
</tr>
<tr>
<th colspan="3"></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<th colspan="3"></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<th colspan="3"></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr>
<th colspan="7"></th>
</tr>
</table>
</body>


Now I am not sure how the script should be written based on the process below, so the question is how should it be written?:

1. detect tr(s) that has 7 ths or tds and remove every last two of them from its' parent tr

2. modify th's attribute rowspan=7 to rowspan=5 due to the removal of ths and tds

3. detect tr(s) that has 5 ths where it hast a first-child th with rowspan=3 attribute and remove every last two of them from its' parent tr.

Appreicate any help in advance!

DoubleJ

rnd me
06-21-2007, 08:18 PM
function tags(tid) {return document.getElementsByTagName(tid);}
function Group (f, List) {var z = 0;Ray = [];len = List.length;for (z; z < len; z++) {if (f(List[z])) {Ray[Ray.length] = f(List[z]);}}return Ray;}

function obValsl(ob) {var r = [];var i = 0;for (var z = 0; z < ob.length; z++) {r[z] = ob[z];}return r;}

function kill(tr) {tr.parentNode.removeChild(tr);}

function obFilter(ob, p) {var r = [];var i = 0;for (var z in ob) {if (ob.hasOwnProperty(z)) {r[i++] = ob[z][p];}}return r;}

var T=tags("table")[0];
var Rs=T.rows;

//1. detect tr(s) that has 7 ths or tds and remove every last two of them from its' parent tr:
Group( function(r){ if(r.cells.length=='7'){kill(r.cells[5]);kill(r.cells[5])}; }, Rs )

//2. modify th's attribute rowspan=7 to rowspan=5 due to the removal of ths and tds.

Group( function(r){if(!!r.colspan && r.colspan==7){r.colspan=5}}, obValsl(tags("th")) )


//3. detect tr(s) that has 5 ths where it hast a first-child th with rowspan=3 attribute and remove every last two of them from its' parent tr.
// I am very confused by this last one. did you mix up TRs and THs in your question? one is horiz, one is vert...

//i will try to get back with you if you can clarify, or mayby this is enough to get you going.


//hope it helps!

DoubleJ
06-23-2007, 03:39 PM
Appreciate the help! My mistake, I meant colspan, not rowspan (typo eh).

What I meant is to:

1. Remove last two TH or TD from TR that has 7 TH or TD, which once process the removal TH/TD, TR then will have just 5 TH or TD instead of 7 TH or TD

2. Again remove last two TH from TR that holds 5 TH where its' first-child TH has colspan=3 attribute to compenstate for above changes

3. Modify all TH with colspan=7 into colspan=5

I'll play around with your script and see if it works or need to thinker a bit. Will let you know if it works or what...

Thanks,

DoubleJ