Click to See Complete Forum and Search --> : Dynamic Script Addition


vmahalin
03-28-2003, 10:23 AM
I am creating cells in a table using the following code -

in a for loop {
var sCell = document.all("Matrix").rows[countRow].insertCell();
//The id of the cell is "Cell" + row + column
sCell.id = "cell" + countRow + countCol;
//The value of the cell is the id again sCell.innerHTML = sCell.id;
}

All of the above is after the load of the document. I want to add some events for each of those cells.

when I explicitly mention -

<SCRIPT FOR=cell00 EVENT='onclick' LANGUAGE="JavaScript">
editCell(this);
</SCRIPT>

The method "editCell(this)" evokes fine for the cell with an id cell00. (row=0 column=0)

But I want to add the script as the cells are being created. As I would not know as to how many cells I may require.

Can anyone please suggest the way to do it.

Vladdy
03-28-2003, 11:19 AM
IE: node.attachEvent
DOM2 (Gecko browsers): node.addEventListener

vmahalin
03-28-2003, 12:06 PM
AttchEvent does not solve the problem. If some function is associated with lets say 'onclick'. The moment the cell loads , the function is fired.

vmahalin
03-28-2003, 02:03 PM
Thanks, in fact attachEvent worked fine. But there started another problem....

See the code below -

for loop for all rows=10
{
create row object
for loop for all columns=10
{
create cell object;
Assign id;
cellObj.attachevent{}
}
}

In this case only the last cell in the table is associated with the event and the eventhandler in attachEvent. I want for instance, onclick to fire an eventhandler for all cells not only the last one.

If anyone can help...Thanks

Vladdy
03-28-2003, 02:07 PM
access the event target via the event object passed to the attached funciton

vmahalin
03-28-2003, 02:15 PM
Vladdy, thanks a lot for the reply. can you explain it a little more.......really not quite getting what you have written...

the attached function is the one which we mention alongwith attachEvents

But Iam passing the cell as an object in the function not any event object.

Target event is 'onclick' ...if Iam not wrong.

Will be great if you clarified.

vmahalin
03-28-2003, 02:59 PM
Thanks a lot vladdy, I got what had to be done. I made small changes and used the event object to reflect the required cell. And it worked.

Thanks again