maria_megha
07-15-2012, 03:24 PM
hi all,
I am trying to alert the td content of a table . I pass the company Id as the parameter and need to alert the company name.I am able to alert only the first company.What needs to be done.?Please help
<html>
<head>
<script type="text/javascript">
function displayID(id)
{
var match=id.trim();
alert(match);
var table = document.getElementById('MyTable');
for (var r = 0, n = table.rows.length; r < n; r++) {
for (var c = 0, m = table.rows[r].cells.length; c < m; c++) {
alert(table.rows[r].cells[c].innerHTML);
if(table.rows[r].cells[c].innerHTML==match){
alert("Found!");
alert(table.rows[r].cells[c-1].innerHTML)
}
}//for c
}//for r
}
</script>
</head>
<body>
<table border="1" id="MyTable">
<tr>
<td> </td>
<td>Company Name </td>
<td> Company Id </td>
<td>Status </td>
</tr>
<tr>
<td><input type="radio" name="radio_newcontact" id="radio_newcontact" value="ABC" onclick="displayID(this.value)"/></td>
<td id="ABC tradin Co">ABC Trading Co</td>
<td id="ABC">ABC</td>
<td>Active</td>
</tr>
<tr>
<td><input type="radio" name="radio_newcontact" id="radio_newcontact" value="DEF" onclick="displayID(this.value);"></td>
<td id="DEF Co">DEF Co</td>
<td id="DEF"> DEF</td>
<td>Active</td>
</tr>
<tr>
<td><input type="radio" name="radio_newcontact" id="radio_newcontact" value="GHI" onclick="displayID(this.value);"></td>
<td id="GHI LTD">GHI LTD</td>
<td id="GHI"> GHI</td>
<td>Active</td>
</tr>
</table>
</body>
</html>
I am trying to alert the td content of a table . I pass the company Id as the parameter and need to alert the company name.I am able to alert only the first company.What needs to be done.?Please help
<html>
<head>
<script type="text/javascript">
function displayID(id)
{
var match=id.trim();
alert(match);
var table = document.getElementById('MyTable');
for (var r = 0, n = table.rows.length; r < n; r++) {
for (var c = 0, m = table.rows[r].cells.length; c < m; c++) {
alert(table.rows[r].cells[c].innerHTML);
if(table.rows[r].cells[c].innerHTML==match){
alert("Found!");
alert(table.rows[r].cells[c-1].innerHTML)
}
}//for c
}//for r
}
</script>
</head>
<body>
<table border="1" id="MyTable">
<tr>
<td> </td>
<td>Company Name </td>
<td> Company Id </td>
<td>Status </td>
</tr>
<tr>
<td><input type="radio" name="radio_newcontact" id="radio_newcontact" value="ABC" onclick="displayID(this.value)"/></td>
<td id="ABC tradin Co">ABC Trading Co</td>
<td id="ABC">ABC</td>
<td>Active</td>
</tr>
<tr>
<td><input type="radio" name="radio_newcontact" id="radio_newcontact" value="DEF" onclick="displayID(this.value);"></td>
<td id="DEF Co">DEF Co</td>
<td id="DEF"> DEF</td>
<td>Active</td>
</tr>
<tr>
<td><input type="radio" name="radio_newcontact" id="radio_newcontact" value="GHI" onclick="displayID(this.value);"></td>
<td id="GHI LTD">GHI LTD</td>
<td id="GHI"> GHI</td>
<td>Active</td>
</tr>
</table>
</body>
</html>