Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check match when changing field 1

Status
Not open for further replies.

stewartwebb

Programmer
Jan 6, 2004
92
GB
Hi,

I have a <tr> on my page which is in a 'rows' tag and being loaded depending on how many records are on a file. So there could be many <tr> down the page.

The user can the select a value within 1 of the <td>'s within the <tr> which opens a mini window which they then enter a new value for that <td> selected.

As there are many rows what I want to do is loop through the <td>'s in the column that the use just selected to check if the value matches the value they have just entered.

The problem is the value which they just selected can also be in a different <td> in a different column, otherwise i could have just looped through all the <td> within the table.

I hope this makes sence, thanks

Stewart
 
I haven't tested this, but maybe something like this, where colIndex is the number of the column you wish to search (starting with zero)
Code:
function isValueInColumn(value,colIndex){
  var tbl = document.getElementById("myTable");
  var trs = document.getElementsByTagName("TR");
  for(i=0;i<trs.length;i++){
    var tds = trs[i].getElementsByTagName("TD");
    if(colIndex >= tds.length) continue; // Not enough columns, so skip this row
    if(value==tds[colIndex]) return true;
  }
  return false;
}

Adam
 
Thanks, The code isn't exactly right but i've changed it a bit and it now works how I want it too, brillant.

Stewart
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top