How do you dynamically assign a function to an element's event with
specific parameters?
I know that the code is different for MSIE and Mozilla, and need to know
how to do this for both.
I have the following event handler functions defined and need to assign
them to table elements (<TD>) created dynamically in another function.
function handleMouseOver(elt, cssClass, strURL)
{
....
}
handleMouseOut(elt, cssClass)
{
....
}
handleMouseDown(elt, cssClass)
{
....
}
handleMouseUp(elt, cssClass, strURL)
{
....
}
The code frag below is where they need to be assigned.
Thanks,
N. Demos
Example (Code Fragment):
-------------------------
for(i = 0; i < 5; i++){
// Construct 'TR' Node
var eltNewRow = document.createElement('TR');
eltNewRow.id = (strMenuID + '-SUBMENU_BUTTON' + i);
// Construct 'TD' Button
var eltButton = document.createElement('TD');
eltButton.appendChild(document.createTextNode('Sub Button ' + (i +
1)));
eltButton.className = 'subNavNormButton';
var strTargetURL = arrayURLList[i];
// ***** Assign Mouse Event Handlers *****
eltButton.onmouseover = handleMouseOver(this, 'subNavHoverButton',
strTargetURL);
eltButton.onmouseout = handleMouseOut(this, 'subNavNormButton');
eltButton.onmousedown = handleMouseDown(this, 'subNavPressButton');
eltButton.onmouseup = handleMouseUp(this, 'subNavHoverButton',
strTargetURL);
// Insert Element Into Tree
eltNewRow.appendChild(eltButton);
if(eltInsertionRow && parentMenu){
parentMenu.insertBefore(eltNewRow, eltInsertionRow);
}
else if(parentMenu){
parentMenu.appendChild(eltNewRow);
}
}
--
Change "seven" to a digit to email me.