473,405 Members | 2,171 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,405 software developers and data experts.

SetAttribute doesn't work, please help

RC
Please look at this page: http://www.norbertverboeket.com/test

There are 2 stylesheets, StyleSheet.css and BigStyle.css. One is
copied from the other. Only the font-size is changed, so there
couldn't be anything wrong with the copy.

When the user clicks on 'Click here', the function SwitchSheets should
switch the stylesheets:
document.all["ScreenStyle"].SetAttribute("HREF", "BigStyle.css",0);

The only thing I get is 'error on page'.

I have IE 6. What am I doing wrong here?
Oct 3 '06 #1
5 1967
VK

RC wrote:
Please look at this page: http://www.norbertverboeket.com/test
When the user clicks on 'Click here', the function SwitchSheets should
switch the stylesheets:
document.all["ScreenStyle"].SetAttribute("HREF", "BigStyle.css",0);

The only thing I get is 'error on page'.

I have IE 6. What am I doing wrong here?
JavaScript/JScript is case-sensitive and the relevant method name is
called setAttribute (small "s"). Be very careful with MSDN samples for
JScript: they are plain of case typos as some sections seem to be made
by pure VB guys who missed to switch the mind on time. Some parts are
really funny in this matter, like say FileSystemObject specs: here
proper case/ case mishmash are going from method to method
alphabetically. Evidently it was made by two people with C++ practice
and VB practice respectively, so the correcteness depended on who came
back from the coffee break. :-)

Also document.all is IE-specific collection. The rest of the civilized
word :-) is using document.getElementById method.

Here is a working sample for both IE and Firefox (you need sheet1.css
and sheet2.css with different rules for P element to see the effect):

<html>
<head>
<title>CSS Switch</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">

<link id="mySheet" rel="stylesheet" href="sheet1.css">

<script type="text/javascript">
function changeSheet() {
var mySheet = document.getElementById('mySheet');
if (('undefined' == typeof mySheet.main) || (mySheet.main)) {
mySheet.href = 'sheet2.css';
mySheet.main = false;
}
else {
mySheet.href = 'sheet1.css';
mySheet.main = true;
}
}
</script>
</head>

<body>
<p>Sample</p>
<button type="button" onClick="changeSheet()">Change
stylesheet</button>
</body>
</html>

Oct 3 '06 #2
Hi,

RC wrote:
Please look at this page: http://www.norbertverboeket.com/test

There are 2 stylesheets, StyleSheet.css and BigStyle.css. One is
copied from the other. Only the font-size is changed, so there
couldn't be anything wrong with the copy.

When the user clicks on 'Click here', the function SwitchSheets should
switch the stylesheets:
document.all["ScreenStyle"].SetAttribute("HREF", "BigStyle.css",0);
document.all is IE only, deprecated, and should be avoided like the
plague if you ask me. document.getElementById is the way to go. But
that's not the cause for the error.

JavaScript is case sensitive, and follows the Java naming conventions.
Use camel notation, not pascal notation:

setAttribute( ... );

Note also that you should check if the result of
document.getElementById( ... ) is null.

HTH,
Laurent
>
The only thing I get is 'error on page'.

I have IE 6. What am I doing wrong here?
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Oct 3 '06 #3
Hi,

VK wrote:
JavaScript/JScript is case-sensitive and the relevant method name is
called setAttribute (small "s"). Be very careful with MSDN samples for
JScript: they are plain of case typos as some sections seem to be made
by pure VB guys who missed to switch the mind on time.
FileSystemObject uses the Pascal notation. The documentation is correct
in that matter.

HTH
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Oct 3 '06 #4
RC
Thanks Laurent, that was it. I have it from the 'Developing web
applications with Microsoft Visual Basic.Net and c#' book, so I guess
you're not surprised that I used this 'Microsoft' Java code. But
anyway, I'll try to avoid it next time.

On Tue, 03 Oct 2006 23:08:15 +0200, Laurent Bugnion
<ga*********@bluewin.chwrote:
>Hi,

RC wrote:
>Please look at this page: http://www.norbertverboeket.com/test

There are 2 stylesheets, StyleSheet.css and BigStyle.css. One is
copied from the other. Only the font-size is changed, so there
couldn't be anything wrong with the copy.

When the user clicks on 'Click here', the function SwitchSheets should
switch the stylesheets:
document.all["ScreenStyle"].SetAttribute("HREF", "BigStyle.css",0);

document.all is IE only, deprecated, and should be avoided like the
plague if you ask me. document.getElementById is the way to go. But
that's not the cause for the error.

JavaScript is case sensitive, and follows the Java naming conventions.
Use camel notation, not pascal notation:

setAttribute( ... );

Note also that you should check if the result of
document.getElementById( ... ) is null.

HTH,
Laurent
>>
The only thing I get is 'error on page'.

I have IE 6. What am I doing wrong here?
Oct 4 '06 #5
Hi,

RC wrote:
Thanks Laurent, that was it. I have it from the 'Developing web
applications with Microsoft Visual Basic.Net and c#' book, so I guess
you're not surprised that I used this 'Microsoft' Java code. But
anyway, I'll try to avoid it next time.
It's not Java, it's JavaScript. Very different animal, though they use
similar notations.

Greetings,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Oct 4 '06 #6

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

Similar topics

3
by: timmy_dale12 | last post by:
Hello , im a java programmer whos gotten tangled up in some javascripts. Im really stuck on this one can , can aybody explain this to me. I have a javscript which is to clone a table row and...
2
by: fj | last post by:
I have no problem nevigate and neil down the element I want to manipulate. What I want to do is set the css class of an item according to window.location (URL). But it doesn't work. I call...
6
by: Pugi! | last post by:
I use mycurrent_cell.setAttribute("style", "background-color:green"); and mycurrent_cell.setAttribute("colspan", "3"); to set some attributes of a table. The code works perfect in FireFox and...
5
by: gkelly | last post by:
Can someone explain what I am doing wrong, or why this will not work? I've tested this in IE6, Firefox 1.5 and Mozilla 1.7, all with the same result. Take for example this code: <html>...
11
by: jesdynf | last post by:
I'm having trouble applying a stylesheet to content I'm generating after the fact. Here's the sample code: <html> <head> <title>CSS/DOM Problem Example</title> <style type="text/css">...
2
by: Aaron Gray | last post by:
Whats going on with setAttribute on IE it appears to work on some examples and working code but not on other code that I am writting ? <style> .foo { font-size: 200%; } </style>
4
by: ICPooreMan | last post by:
I've got some code which works in firefox that's giving me fits in IE7 (maybe other versions too I haven't tested it). What I want to do is get the oncontextmenu attribute of something, change the...
2
by: nygiantswin2005 | last post by:
Hi I have wrote a method in my C# class with the following code, to create an XMl file. The root element is suppose to have 3 attibutes. I can not get attributes to appear correctly. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.