View Full Version : onBlur event works in FireFox but not in IE6 on WindowsXP

06-04-2004, 12:07 PM
A simple script to test:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="javascript">
var numRows = 0;
function regelToevoegen(){
var arrFields = new Array(
new Array(true, 'veld1', false),
new Array(true, 'veld2', true),
new Array(true, 'veld3', false));
var theTable = document.getElementById('theTable');
var newPos = theTable.rows.length-1;
var newRow = theTable.insertRow(newPos);
for(var i=0; i<arrFields.length; i++){
var newCell = newRow.insertCell(i);
var tempName = arrFields[i][1] + '[' + numRows + ']';
var newEl = document.createElement('input');
newEl.setAttribute('type', 'text');
newEl.setAttribute('name', tempName);
newEl.setAttribute('id', tempName);
newEl.setAttribute('size', 10);
if(arrFields[i][2]!=null && arrFields[i][2]==true){
newEl.setAttribute("onBlur", "alert('onBlur event!')");
<style media="all">
text-align: center;
td, th{
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;

<form action="<? print $_SERVER['PHP_SELF']; ?>" method="post" name="formTest" id="formTest">
<table id="theTable" width="500" border="0" cellspacing="1" cellpadding="5">
<th width="30%">kolom 1</th>
<th width="30%">kolom 2</th>
<th width="30%">kolom 3</th>
<td colspan="3" align="center"><a href="javascript:void(0);" onClick="javascript:regelToevoegen();">rij toevoegen</a></td>
<input type="submit" name="Submit" value="Submit">
<? print_r($_POST); ?>

When you add a row, 3 tablecells are generated.
The second cell should have an onBlur-event.

It works well in FireFox, but not in IE6 on Windows XP.

Does anyone know how I can make this work?


06-04-2004, 07:37 PM
Change this:
newEl.setAttribute("onBlur", "alert('onBlur event!')");To this:
newEl.onblur = function() { alert('onBlur event!'); }

06-07-2004, 03:15 PM
Thisn worked eventually:

newEl.onblur = new Function("alert('hello')");

06-08-2004, 04:08 AM
Why use constructor notation? That's less efficent than the annoymous function notation I provided above.

06-08-2004, 05:45 AM
fredmv is right. Function constructor is similar to eval in behavior.