View Single Post
Old 10-12-2012, 08:07 PM   PM User | #19
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
yes, and in that file you call the addLoadListener function.

But sorry - I misread it, and it works fine (that function call does actually attach a window onload listener). There's obviously a problem somewhere else. Here's your code with the other bits taken out:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script>
function addLoadListener(fn){
  if (typeof window.addEventListener != 'undefined')  {
    window.addEventListener('load', fn, false);
  }
  else if (typeof document.addEventListener != 'undefined')  {
    document.addEventListener('load', fn, false);
  }
  else if (typeof window.attachEvent != 'undefined')  {
    window.attachEvent('onload', fn);
  }
};

function attachEventListener(target, eventType, functionRef, capture){
  if (typeof target.addEventListener != "undefined")  {
    target.addEventListener(eventType, functionRef, capture);
  }
  else {
    target.attachEvent("on" + eventType, functionRef);
  }
  return true; 
};

function  validateForm(){
	 var therows=document.getElementById("mytable").rows;
	 for (var i = 0; i < therows.length; i++) {
		 attachEventListener(therows[i],'mouseover',function(){this.style.backgroundColor="red"});
		 attachEventListener(therows[i],'mouseout',function(){this.style.backgroundColor="white"});
	}
};

addLoadListener(validateForm);
</script>
</head>
<style>
td{width:30%}
</style>
</head>
<body>
<table id="mytable" width="75%" border="1">
  <tr>
    <td>Name</td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td>Age</td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td>Job</td>
    <td></td>
    <td></td>
  </tr>
</table>
</body>
</html>
still doesn't work in IE, though, whereas the other attach event code does.

what does your error console say?
xelawho is offline   Reply With Quote