theEclipse
Programmer
I have this function:<br><br>function readIn(){<br>// the variables.<br>var table=new Array();<br>var row=-1,col=-1,rloop=true,cloop=true;<br><br>//this variable, str holds the table's original html throughout the function<br>var str=document.all.theTable.innerHTML.toLowerCase();<br><br>//edited is the string that gets edited in the function.<br>var edited=str<br><br>//remove all of the new line, and carrage return characters<br>var reg=/(\r)¦(\n)/g<br>str=str.replace(reg,'');<br><br>//loop through the rows of the table<br>while (rloop){<br> row++;<br><br>//make the current slot of the table array contain an array.<br>//(sort of an on the fly 2-d array maker)<br> table[row]=new Array();<br><br>//delete everything before the end of the first <tr> tag<br> edited=edited.substring(edited.indexOf('<tr>')+4,edited.length);<br><br>//loop through each cell in the current row<br> while (cloop){<br> col++;<br><br>//delete everything before the end of the next <td> tag<br> edited=edited.substring(edited.indexOf('<td>')+4,edited.length);<br><br>//put the current cells data in the coresponding array slot<br> table[row][col]=edited.substring(0,edited.indexOf('</td>'));<br><br>//delete everything before the end of the next </td> tag (probably not necessary)<br> edited=edited.substring(edited.indexOf('</td>')+5,edited.length);<br><br>//if we have reached the end of the row, exit the inner loop<br> if (edited.indexOf('<td>')>edited.indexOf('</tr>') ¦¦ edited.indexOf('<td>')==-1) {cloop=false}<br> }//the end of the inner loop (for the cells)<br><br>//delete everything before the end of the next </tr> tag (also probably not necessary)<br> edited=edited.substring(edited.indexOf('</tr>')+5,edited.length);<br><br>//if we have reached the end of the table, dont run the loop again, otherwise, make sure the inner loop runs again.<br> if (edited.indexOf('<tr>')==-1) {rloop=false} else {cloop=true}<br><br>}// the end of the outer while loop<br><br>//the next 10 lines are just to make a string from the array and print it out to the webpage.<br>var str='<table border=2>';<br>for (k=0; k<table.length; k++){<br>str+='<tr>';<br>for (j=0; j<table[k].length; j++){<br>str+='<td>'+table[k][j]+'</td>';<br>}<br>str+='</tr>';<br>}<br>str+='</table>';<br>document.write(str);<br><br>}//the end of the function.<br><br><br>the only problem with the function is that when it is reading in the table, it adds cells. for example, if you have a 2*3 table, when the loops read in this table you get something like this:<br><br>----------------<br>¦cell0-1¦cell0-2¦<br>---------------------------------<br>¦-------¦-------¦cell1-1¦cell1-2¦<br>-------------------------------------------------<br>¦-------¦-------¦-------¦-------¦cell2-1¦cell2-2¦<br>-------------------------------------------------<br><br>except the cells with dashes are just undefined.<br><br>can somebody please helllllppppp? <p>theEclipse<br><a href=mailto:eclipse_web@hotmail.com>eclipse_web@hotmail.com</a><br><a href=robacarp.webjump.com>robacarp.webjump.com</a><br>**-Trying to build a documentation of a Javascript DOM, crossbrowser, of course. E-mail me if you know of any little known events and/or methods, etc.