...

View Full Version : <TABLE>'s Row Id



dpkbahuguna
05-07-2008, 05:05 AM
Hello friends!!

I'm creating <Table> through java script...and now I have to get mouse click event from it...as I click on the any row then i should get the ID of that row..

Could anyone help me for that my code is for creating the <table> here below:

-----------------------------------------------------------
//in obj variable i m passing the array.


function RetFun(Obj)
{
if(Inc == 'NO')
{
var cnt = document.getElementById('Table_JobOrderDet').rows.length;
for(i1=0;i1<cnt;i1++)
document.getElementById('Table_JobOrderDet').deleteRow(0);
}
Inc = 'NO';



DataVar = Obj.value;
var TotRows = new Array();
alert('one');
alert(Obj.value);
alert('Two');
TotRows = DataVar.split("~~~");
alert('TotRows.length');
var DetTab = document.getElementById('Table_JobOrderDet').insertRow(0);
var ColJobNo = DetTab.insertCell(0);
var ColMsg= DetTab.insertCell(1);
var ColMsgDt = DetTab.insertCell(2);
var ColToName = DetTab.insertCell(3);
var ColFrmName = DetTab.insertCell(4);
var ColSno = DetTab.insertCell(5);
ColJobNo.innerHTML = "JOB NO.";
ColMsg.innerHTML = "MESSAGE";
ColMsgDt.innerHTML = "DATE";
ColToName.innerHTML = "FROM";
ColFrmName.innerHTML = "TO";
ColSno.innerHTML = "SNO";

for(i=0; i<TotRows.length; i++)
{

var DetTab = document.getElementById('Table_JobOrderDet').insertRow(i+1);
var ColJobNo = DetTab.insertCell(0);
var ColMsg= DetTab.insertCell(1);
var ColMsgDt = DetTab.insertCell(2);
var ColToName = DetTab.insertCell(3);
var ColFrmName = DetTab.insertCell(4);
var ColSno = DetTab.insertCell(5);

var cols = new Array();
cols = TotRows[i].split("^^^");
for(j=0; j<cols.length; j++)
{
if(j == 0)
ColJobNo.innerHTML = cols[j];
else if(j == 1)
ColMsg.innerHTML = cols[j];
else if(j == 2)
ColMsgDt.innerHTML = cols[j];
else if(j == 3)
ColToName.innerHTML = cols[j];
else if(j == 4)
ColFrmName.innerHTML = cols[j];
else if(j == 5)
ColSno.innerHTML = cols[j];
}
}
}

-----------------------------------------------------------

fside
05-07-2008, 01:01 PM
Assuming the job number is a unique ID, you can just get the job number value from the first cell by clicking on that row.

So insert this line:

var DetTab = document.getElementById('Table_JobOrderDet').insertRow(i+1);
DetTab.onclick = function(){ fAlert(this) }; /* <------ insert here */
var ColJobNo = DetTab.insertCell(0);


Add an fAlert - or whatever you want the function to be:

function fAlert(whId){ alert(whId.firstChild.firstChild.nodeValue); }

Here it's looking for the first TD, first col, under the TR on which you clicked.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum