[Javascript] attach actions to all objects in a form?
Roger Roelofs
rer at datacompusa.com
Wed May 26 13:12:09 CDT 2004
Shawn,
On May 26, 2004, at 1:52 PM, Shawn Milo wrote:
> Is there a way to write an onclick function, or something
> similar, so that it applies to all objects on a form?
>
Yes,
I'm using code that does this to provide a hover effect on long tables
to highlight the line the user has pointed at. The code goes something
like this...
/// setup
var el = document.getElementById("theContainer");
if (el) {
if( el.addEventListener ) {
el.addEventListener("click", clickableTableRowClick, false);
} else {
if(el.attachEvent) {
el.attachEvent("onclick", clickableTableRowClick);
} else {
el.onclick = clickableTableRowClick;
}
}
}
// callback routine
function clickableTableRowClick(evt) {
var targ, oldRow;
if (!evt) evt = window.event;
if (evt.target) targ = evt.target;
else if (evt.srcElement) targ = evt.srcElement;
...
do what you want with the target element
More information about the Javascript
mailing list