HighDots Forums  

Re: javascript onChange event does not work in IE

Javascript JavaScript language (comp.lang.javascript)


Discuss Re: javascript onChange event does not work in IE in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Lasse Reichstein Nielsen
 
Posts: n/a

Default Re: javascript onChange event does not work in IE - 05-02-2004 , 05:48 PM






"rick" <rmsingh (AT) no_spam_rogers (DOT) com> writes:

Quote:
The following basic script works fine in firefox by not in IE. Can anyone
spot the problem?
A guess:

Quote:
function addRowToTable(){
var tbl = document.getElementById('itemlist');
var lastRow = tbl.rows.length;
var row = tbl.insertRow(lastRow);

// qty cell
var qty2 = row.insertCell(0);
var el_qty = document.createElement('input');
el_qty.setAttribute('type', 'text');
IE doesn't translate values set with setAttribute to operative values.
To make it work in IE, you should write
el_qty.type = "text";
It should also work for modern browsers, as long as the property is
part of the W3C DOM 2 HTML specification.

My guess at what goes wrong is that ...

Quote:
D.setAttribute('onClick','removeRowFromTable(this) ');
... it will definitly not recognize this one. Use this instead:
---
D.onclick = function(){removeRowFromTable(this);};
---

Quote:
function getRowIndex (cell) {
return document.all ? cell.parentElement.rowIndex :
cell.parentNode.rowIndex;
You are using the existence of document.all to decide whether to use
cell.parentElement or cell.parentNode. What about non-IE browsers that
has document.all but not cell.perentElement (I don't know if there are
any, but I don't know that there isn't either).

Just test for the property you need, with a fallback if it isn't there:
---
function getRowIndex(cell) {
return (cell.parentNode || cell.parentElement).rowIndex;
}
---

/L
--
Lasse Reichstein Nielsen - lrn (AT) hotpop (DOT) com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'


Reply With Quote
  #2  
Old   
Richard Cornford
 
Posts: n/a

Default Re: javascript onChange event does not work in IE - 05-03-2004 , 10:21 AM






rick wrote:
Quote:
"Lasse Reichstein Nielsen" wrote:
snip
D.onclick = function(){removeRowFromTable(this);};

This does not work either same reason I think? below is the
modified sample that tried.
snip
el_qty.onChange = function(){calc_total();};
snip

The attribute names for intrinsic events are case insensitive in HTML
but the corresponding DOM object property names are traditionally (and
mostly implemented as) all lower case. The above assignment would be
expected to create an - onChange - property and assign a reference to
the function to that property, but the function will not be called in
response to change events.

Richard.




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.