Javascript How-ToAsk your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Am creating a table dynamically using vbscript (asp.net). The row ids and column ids are created at runtime. On the click of a column,
a javascript function is called. In this function i successfully trapped the column which was clicked. But i need to trap the column text. How do i do this? The partial code is here:
For row = 0 To dt.Rows.Count - 1 'displaying rows
Response.Write("<tr id=RowId" & row+1 & " onclick=TrapId(id)>")
For col = 0 To dt.Columns.Count - 1 'displaying columns
Response.Write("<TD id=ColId" & col+1 & " onclick=TrapId(id)>" & dt.Rows(row)(col).ToString & "</TD>")
Thanks Snib. But i have a problem. When i write document.getElementById(id).innerHTML it gives we the contents of the entire row. Even while using innerText it gives the entire row contents whereas i want to trap only the column value where clicked. PLease help!!!
function AlertColText(cell){
var colText = "";
var rows = cell.parentNode.parentNode.getElementsByTagName("tr");
for(var i = 0; i < rows.length; i++){
var cells = rows.item(i).getElementsByTagName("td");
colText += cells.item(cell.cellIndex).innerHTML + "\n";
}
alert(colText);
}