arunsmartarrow

Search

Sep 6th, 2013
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. function doSearch() {
  2.  
  3. var searchText = document.getElementById('searchTerm').value;
  4. var targetTable = document.getElementById('mytable');
  5. var targetTableColCount;
  6.  
  7. //Loop through table rows
  8. for (var rowIndex = 0; rowIndex < targetTable.rows.length; rowIndex++) {
  9. var rowData = '';
  10.  
  11. //Get column count from header row
  12. if (colIndex == 0) {
  13. targetTableColCount = targetTable.rows.item(rowIndex).cells.length;
  14. continue; //do not execute further code for header row.
  15. }
  16.  
  17. //Process data rows. (rowIndex >= 1)
  18.  
  19. //If search term is not found in row data
  20. //then hide the row, else show
  21. if (rowData.indexOf(searchText) == -1)
  22. targetTable.rows.item(rowIndex).style.display = 'none';
  23. else
  24. targetTable.rows.item(rowIndex).style.display = 'table-row';
  25. }
  26. }
  27.  
  28. Is this Correct to search only First Column
Advertisement
Add Comment
Please, Sign In to add comment