473,379 Members | 1,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

DOM & onclick in IE6

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

Nov 23 '05 #1
5 1569

ne****@googlemail.com wrote:
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;

Nov 23 '05 #2
ne****@googlemail.com wrote:
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
}
--
Rob
Nov 23 '05 #3


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
Nov 23 '05 #4
On 2005-11-12, ne****@googlemail.com <ne****@googlemail.com> wrote:
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>


try 'onClick' instead of 'onclick'?

or mybutton.onClick='myfunction()';
--

Bye.
Jasen
Nov 23 '05 #5
Jasen Betts wrote:
On 2005-11-12, ne****@googlemail.com <ne****@googlemail.com> wrote:
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>
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
Nov 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: David List | last post by:
I'm having a problem using different properties of the document object in the example javascripts in my textbook with browsers that identify themselves as using the Mozilla engine. One example of...
2
by: JoRo | last post by:
Hi, I'm trying to add an onclick event to a button control so it will open up a new popup window. Everything works fine except where I add variables to pass on to the popup window. Where I have...
2
by: Mike | last post by:
My page populates a table with a list of names and other information from a JavaScript object. I receive changes (adds, change & delete) to that list, convert it into a JavaScript object. I do...
9
by: Astra | last post by:
Hi everybody Wonder if you could help me out. I created a simple JavaScript routine to enable a user to click backwards and forwards between small news articles. This routine works fine in IE...
0
by: dnphamus13 | last post by:
I'm new to this and drowning right now. I would like to put my database online for viewing. I managed to do the filtering but i need to do PAGING as the XML doc get bigger. From what i understand...
7
by: bhavin30 | last post by:
Is there a way to obtain user information (using LOGON_USER server variables) when you have set up the security to Anonymous Access? I have tried setting the security to both Anonymous + Window...
3
by: jnag | last post by:
Hello, I have a website with various font options (small to large) buttons that the user can click on the banner, which runs through the site. Site contains both static and dynamic content. I...
3
by: Nathan Sokalski | last post by:
I am adding an onmouseover attribute using the Attributes.Add() method, and the String I am using for the value contains the & character. However, when rendered the & is converted to the HTML...
3
by: pyro169 | last post by:
Hey I am making a tic tac toe game, im new to javascript, and when i make the game with 'buttons' and 'x' and 'o' it works perfectly, but i also made some pics and i can get the pics to show up, but...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.