Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-07-2008, 04:05 AM   PM User | #1
dpkbahuguna
New Coder

 
Join Date: Mar 2008
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
dpkbahuguna is an unknown quantity at this point
<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 08:43 AM.. Reason: wrap the code [code][/code]
dpkbahuguna is offline   Reply With Quote
Old 05-07-2008, 12:01 PM   PM User | #2
fside
Regular Coder

 
Join Date: Mar 2008
Posts: 301
Thanks: 2
Thanked 30 Times in 30 Posts
fside is an unknown quantity at this point
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 03:19 PM..
fside is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:51 PM.


Advertisement
Log in to turn off these ads.