Click to See Complete Forum and Search --> : Click event


lakshman
05-07-2003, 03:39 AM
Hi all

I am creating "an onclick event" dynamicaly. but it does not work.

I am doing the following.....

function createResultTable()
{

var oTBody = document.getElementById("tblSrchResutl_tBody");


oTR = oTBody.insertRow();
oTR.onclick = "populateData()";
oTD = oTR.insertCell().innerText = applDetails[0];
oTD = oTR.insertCell().innerText = applDetails[1];
oTD = oTR.insertCell().innerText = applDetails[2];
oTD = oTR.insertCell().innerText = applDetails[3];
oTD = oTR.insertCell().innerText = applDetails[4];
oTD = oTR.insertCell().innerText = applDetails[5];
.
.
.
}

function populateData()
{
alert("Populate Data Called");
}

The table is displaied OK.

Pleae help....!!!

gil davis
05-07-2003, 06:38 AM
oTR.onclick = "populateData()";I believe it should beoTR.onclick = populateData;

lakshman
05-08-2003, 12:10 AM
Hi gil

Thanks for that It works....!!!!

Thank you very much.

lakshman
05-08-2003, 03:29 AM
Hi All,

Furthur to setting oTR.onclick = populateData dynamically...

How do i

<tr onclick=populateData(0) />
<tr onclick=populateData(1) />
<tr onclick=populateData(2) />
<tr onclick=populateData(3) />


The reason is because I need to know which row the user clicked.

Please help I have banged my head on the wall all day.

Any help will be appreciated.

gil davis
05-08-2003, 05:58 AM
That is a different problem altogether. You would have to rewrite the function to accept the parameter. Or rewrite the function to use the "this" operator.function populateData(it) {
it.innerHTML = "whatever";
}
...
<td onclick="populateData(this)"></td>If there is some special thing for a given TD, just give the TD an ID and inspect the object's ID inside the function.if (it.id == "td1") ...

lakshman
05-08-2003, 07:00 PM
Hi Gil,

Thanks for your reply.

This is just great.

Thank you very much. We have a demo today (9/5/2003) lets hope everything goes well..

Thanks to dave, kalid and yourself for helping me through.