473,395 Members | 1,568 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,395 software developers and data experts.

setAttribute works in FF but not in IE

Hello Forum,

I am using FireFox 3.0.1 and Internet Explorer 7.0. My operating system is Vista. My application is using client-side Javascript. It asks many questions of the user and saves user responses in variables. When the user has answered all questions, a report is produced directing the user to take action based on his answers to the questions.

Because there are very many questions, these are not presented all at one time. Instead they are grouped in a series of tables, each of which is presented in succession. By using code like this, for example:

Expand|Select|Wrap|Line Numbers
  1.     function showHideFormsA() {
  2.         neededId = document.getElementById("adpf2");
  3.         neededId.style.display="inline";
  4.         neededId = document.getElementById("adpf3");
  5.         neededId.style.display="none";
  6.         neededId = document.getElementById("adpf4");
  7.         neededId.style.display="none";
  8.         neededId = document.getElementById("adpf9");
  9.         neededId.style.display="inline";
  10.     }
  11.  
only the forms and tables within the forms that use the CSS "style.display='inline'" appear on the browser screen for the user to interact with. By changing 'inline' and 'none' in succession, the user is presented groups of questions at a time. He sees only the 'inline' questions. All others seem nonexistent.

With each group of questions there are different background colors that are displayed. The code to change colors is like this:
Expand|Select|Wrap|Line Numbers
  1.     function setColor1() {
  2.         neededId = document.getElementById("bodyadp001");
  3.          neededId.setAttribute("bgcolor","#FFFF78");
  4.         neededId = document.getElementById("adptable2");
  5.          neededId.setAttribute("bgcolor","#FFFF78");
  6.         neededId = document.getElementById("adptable9");
  7.          neededId.setAttribute("bgcolor","#FFFF78");
  8.     }
  9.  
This code uses the above color for the 'inline' group of questions on the screen. When the user has completed those questions, he presses a NEXT button and moves to the next group of questions. The scripts activated by the NEXT button cause the previous questions to be hidden by changing them to display='none' and cause the next group to applear by changing them to display='inline'. Different colors correspond to each group.

The above code works flawlessly in FF. In IE the system default color is "#FFFFFF", which is plain white. A co-worker and I have looked at the code in the FF debugging add-on tool. It showed that IE was using "#FFFFFF" and ignoring all the setAttribute action.

Since I am very new to Javascript, I am not up on what is unique to FF and not in other browsers. Would that be the problem? That is, is setAttribute not implemented in IE?

Can anyone suggest what to do to get the colors to change in IE?

Thanks much. All answers very appreciated!!

Tom
Aug 13 '08 #1
2 2278
mrhoo
428 256MB
//cross-browser:
Expand|Select|Wrap|Line Numbers
  1. document.setStyle= function(who,what,val){
  2.     if(typeof who== 'string') who= document.getElementById(who);
  3.     if(who && who.style) who.style[what]= val;
  4. }
  5.  
  6. function setColor1(){
  7.     var s=document.setStyle, b='backgroundColor', v= '#FFFF78';
  8.     s('bodyadp001',b,v);
  9.     s('adptable2',b,v);
  10.     s('adptable9',b,v);
  11. }
Aug 13 '08 #2
//cross-browser:
Expand|Select|Wrap|Line Numbers
  1. document.setStyle= function(who,what,val){
  2.     if(typeof who== 'string') who= document.getElementById(who);
  3.     if(who && who.style) who.style[what]= val;
  4. }
  5.  
  6. function setColor1(){
  7.     var s=document.setStyle, b='backgroundColor', v= '#FFFF78';
  8.     s('bodyadp001',b,v);
  9.     s('adptable2',b,v);
  10.     s('adptable9',b,v);
  11. }
Thank you, mrhoo!!

You gave me exactly what I needed. I installed it and it works in both browsers! Even better, you introduced me to a whole new depth of generalization or abstraction in the use of Javascript.

While this works very effectively, I am not sure I understand all that is going on. I will have to study this carefully.

Admin: Please consider this answered.
Aug 13 '08 #3

Sign in to post your reply or Sign up for a free account.

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: Earl Teigrob | last post by:
I am having trouble creating an Attribute on a new node. The NodeObject.SetAttribute(x,y) method does not exist for the "RecordElement" node. What am I missing??? Earl XmlDocument d = new...
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...
4
by: mitch | last post by:
Suppose I have a DOM element, say a td, and I want to add a value to it to be used later. I am unclear on when it's OK to do td.myAttr = "hello"; versus when I need to do ...
21
by: James Black | last post by:
I am curious if there is a benefit to set attributes directly, in my javascript, or to use setAttribute. For example, I have this: var input = document.createElementNS(xhtmlNS, 'input');...
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...
1
by: theS70RM | last post by:
yea i know there is millions of stuff about this on the net, and this isnt really a question but just wanted to see if people had picked up anything similar. This is only for internet explorer,...
2
by: maminx | last post by:
hello all, i have this script below var td = document.createElement('td'); var theInput = document.createElement('input'); theInput.setAttribute('type', 'text');...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.