in reply to CGI combining javascript

I'd make a function of it, and execute it when the document finishes loading:
function add_handlers { var rows = document.getElementsByTagName('tr'); for (var i = 0; i < rows.length; i++) { rows[i].onmouseover = function() { this.className += 'hilite'; } rows[i].onmouseout = function() { this.className = this.className.replace('hilite', ''); } } }
<body onload="add_handlers();">
If onload works on tables too, you could execute the function when the table finishes loading.

Replies are listed 'Best First'.
Re^2: CGI combining javascript
by Anonymous Monk on Nov 17, 2005 at 15:36 UTC
    think i am making a bit of a mess of it. This is what i have:
    use CGI qw(:standard); print header(); #$JSCRIPT=<<END; print <<EOF; <script> function add_handlers { var rows = document.getElementsByTagName('tr'); for (var i = 0; i < rows.length; i++) { rows[i].onmouseover = function() { this.className += 'hilite'; } rows[i].onmouseout = function() { this.className = this.className.replace('hilite', ''); } } } </script> EOF print start_html( -title=>'KEGG Connection', -style=>{-src=>'style.css'}, ); print "<body onload=\"add_handlers();\">"; do the perl stuff and print table.
    This implementation does not work, but i am going to guess its wrong the way i have coded. Thanks