...

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



SpartaRotterdam
06-04-2004, 11:07 AM
A simple script to test:



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<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);
if(arrFields[i][0]==true){
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!')");
}
newCell.appendChild(newEl);
}
}
numRows++;
}
//-->
</script>
<style media="all">
td{
text-align: center;
}
td, th{
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
}
</style>
</head>

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


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?

Patrick

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

SpartaRotterdam
06-07-2004, 02:15 PM
Thisn worked eventually:



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

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

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum