Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2008
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts

    <TABLE>'s Row Id

    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.
    Code:
      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];
                    }
                }
            }
    -----------------------------------------------------------
    Last edited by Kor; 05-07-2008 at 09:43 AM. Reason: wrap the code [code][/code]

  • #2
    Regular Coder
    Join Date
    Mar 2008
    Posts
    301
    Thanks
    2
    Thanked 30 Times in 30 Posts
    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.
    Last edited by fside; 05-07-2008 at 04:19 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •