| | |
Comparing two html tables
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
function CompareTables(table1,table2) { var instHasChange = false; for(var i=0; i < table1.rows.length; i++) { var changes =RowExists(table2,table1.rows[i].cells[0].innerHTML,table1.rows[i].cells[1].innerHTML); if(!changes[0]) { table1.rows[i].style.backgroundColor = "red"; instHasChange = true; } else if(changes[1]) { table1.rows[i].style.backgroundColor = "orange"; instHasChange = true; } } for(var i=0; i < table2.rows.length; i++) { var changes = RowExists(table1,table2.rows[i].cells[0].innerHTML,table2.rows[i].cells[1].innerHTML); if(!changes[0]) { table2.rows[i].style.backgroundColor = "#00CC33"; instHasChange = true; } else if(changes[1]) { table2.rows[i].style.backgroundColor = "orange"; instHasChange = true; } } return instHasChange; } function RowExists(table,columnName,columnValue) { var hasColumnOrChange = new Array(2); hasColumnOrChange[0] = false; hasColumnOrChange[1] = false; for(var i=0; i < table.rows.length; i++) { if(table.rows[i].cells[0].innerHTML == columnName) { hasColumnOrChange[0] = true; if(table.rows[i].cells[1].innerHTML != columnValue) hasColumnOrChange[1] = true; } } return hasColumnOrChange; } //note : tables are passed by reference so you just pass them using document.getElementById("tableID") method.
Similar Threads
- searching and comparing from several tables (PHP)
- HTML Tables in JSP (JavaScript / DHTML / AJAX)
- Reading and comparing data from 2 tables (ASP.NET)
- Help Comparing two tables and deleting records not in both (MS SQL)
- SQL query and HTML Tables (PHP)
| Thread Tools | Search this Thread |
ajax ajaxcode ajaxexample ajaxhelp ajaxjspservlets animate automatically beta box browser bug calendar captchaformproblem checkbox child class close column createrange() css cursor debugger dependent disablefirebug dom download dropdown editor element embed engine error events explorer ext file form forms getselection google gwt gxt hiddenvalue highlightedword hint html htmlform ie7 ie8 iframe images internet java javascript javascripthelp2020 jawascriptruntimeerror jquery jsf jsfile jump libcurl math media microsoft mimic object onmouseoutdivproblem onreadystatechange parent paypal pdf php player position post problem programming progressbar regex runtime scroll search security select session shopping size software sql text textarea unicode w3c web website window windowofwords windowsxp wysiwyg \n



