DOM & onclick in IE6

N

neousr

I resolved my previous problems setting the class for buttons.. I need
to write an element.SetAttribute('class','myclass') and a
element.SetAttribute('className','myclass') for in order to make both
IE6 & FireFox 1.07 work well..

I also noticed that FireFox is not case-sensitive while specifying the
attributes (but IE recquires the exact capitalization).

Solved that I'm going mad with the onclick event... I'm building a
table dynamically, and there are certains buttons inside... they work
perfect under FireFox but IE6, agais, is deaf...

mybutton.setAttribute('onclick','myfunction()');

any ideas??? and a lot of thanks in advance
 
W

web.dev

I resolved my previous problems setting the class for buttons.. I need
to write an element.SetAttribute('class','myclass') and a
element.SetAttribute('className','myclass') for in order to make both
IE6 & FireFox 1.07 work well..

I also noticed that FireFox is not case-sensitive while specifying the
attributes (but IE recquires the exact capitalization).

Solved that I'm going mad with the onclick event... I'm building a
table dynamically, and there are certains buttons inside... they work
perfect under FireFox but IE6, agais, is deaf...

mybutton.setAttribute('onclick','myfunction()');

any ideas??? and a lot of thanks in advance

It would be more straight forward (to me at least) if you did the
following instead:

mybutton.onclick = myfunction;
 
R

RobG

I resolved my previous problems setting the class for buttons.. I need
to write an element.SetAttribute('class','myclass') and a
element.SetAttribute('className','myclass') for in order to make both
IE6 & FireFox 1.07 work well..

Seems much simpler to write:

element.className = 'myclass';

and have it work in both (nearly all?) browsers.
I also noticed that FireFox is not case-sensitive while specifying the
attributes (but IE recquires the exact capitalization).

Solved that I'm going mad with the onclick event... I'm building a
table dynamically, and there are certains buttons inside... they work
perfect under FireFox but IE6, agais, is deaf...

mybutton.setAttribute('onclick','myfunction()');

any ideas??? and a lot of thanks in advance

Either:

mybutton.onclick = function() {
// statements
};

or if you want to define the function elsewhere:

mybutton.onclick = myfunction;
...


function myfunction() {
// function statements
}


If you want to define it elsewhere and pass parameters:

mybutton.onclick = function() {
myfunction(parm1, parm2,...);
};
...


function myfunction(var1, var2, ...) {
// statements
}
 
D

Danny

Do take the suggestions from the other 2 fellas, is easier to just do it on
event listening, or implicit binding by .onclick=, can't say I've seen your
class setting using setAttribute() but IE doesn't work well with
setAttribute(), it adds it, but there's no binding or inheriting on the
object, so, if you check for it is there in text as property, but it won't
perform as an object.


Danny
 
T

Thomas 'PointedEars' Lahn

Jasen said:
try 'onClick' instead of 'onclick'?

Since HTML is case-insensitive in this regard, I doubt there would be
difference.
or mybutton.onClick='myfunction()';

No. Element objects do not have an `onClick' property in any HTML DOM.
However, they do have the (proprietary) `onclick' property which accepts
a Function reference:

mybutton.onclick = myfunction;

or

mybutton.onclick = function()
{
myfunction();
};

The standards compliant approach is to add an event listener:

mybutton.addEventListener("click", myfunction, false);

In IE, you can also do:

mybutton.attachEvent("onclick", myfunction);

To ease that, I have written

function registerEvent(o, sEvent, fListener, bUseCapture)
{
var result;

if (o)
{
if (dhtml.isMethodType(typeof o.addEventListener)
&& dhtml.isMethodType(typeof fListener))
{
o.addEventListener(sEvent, fListener, !!bUseCapture);
result = true;
}
else if (dhtml.isMethodType(typeof o.attachEvent)
&& dhtml.isMethodType(typeof fListener))
{
result = o.attachEvent("on" + sEvent, fListener);
}
else
{
o["on" + sEvent] = fListener;
result = (o["on" + sEvent] == fListener);
}
}

return result;
}

Published with <http://pointedears.de/scripts/dhtml.js>.

Example:

if (!registerEvent(mybutton, "click", myfunction, false))
{
// handle problem
}


Please read what was already posted (a day ago!) before you post yourself.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,125
Latest member
VinayKumar Nevatia_
Top