getAttribute("disabled") not working in Netscape

C

CES

All,
I'm at a loss, the code below works in IE but not in Netscape and I'm
unskilled enough not to know why.

Essentially this code looks thru all of the form fields and if the input box
has a attribute of disabled="true", attribute would only be present if the
field was disabled, then the label field's class is changed to a grayed out
color.

--- The first problem seems to be with the v==true statement, I've tried
every variation I can think of but v==true is the only one that works in IE.

--- The second problem is the way IE & Netscape/Opera uses different class
attribute statements, is their a way of using 1 setAttribute statement that
will work in IE and Netscape as apposed to:

setAttribute("className", "xxx") for IE
and
setAttribute("class", "xxx") for Netscape

Any Help on these issues will be appreciated.

CES


function fDisableLable(){
for(var a = 0;a < document.forms.length;a++){
var fname = document.forms[a].name;
var f = document.forms[fname];
for(c = 0;c < f.length;c++){
var x = f.elements[c].id;
if(x!=""){
var v = f.elements[x].getAttribute("disabled")
var t = f.elements[x].getAttribute("type")

//This is where I'm having the problem
if((v==true)&&(t!="button")&&(t!="submit")){
//ie version
document.getElementById(x +
'Lable').setAttribute("className", "dataLable_TextDisabled");
//netscape version
document.getElementById(x +
'Lable').setAttribute("class", "dataLable_TextDisabled");
}
}
}
}
}
 
D

DU

CES said:
All,
I'm at a loss, the code below works in IE but not in Netscape and I'm
unskilled enough not to know why.

Essentially this code looks thru all of the form fields and if the input box
has a attribute of disabled="true", attribute would only be present if the
field was disabled, then the label field's class is changed to a grayed out
color.

--- The first problem seems to be with the v==true statement, I've tried
every variation I can think of but v==true is the only one that works in IE.

--- The second problem is the way IE & Netscape/Opera uses different class
attribute statements, is their a way of using 1 setAttribute statement that
will work in IE and Netscape as apposed to:

setAttribute("className", "xxx") for IE
and
setAttribute("class", "xxx") for Netscape

Do not use setAttribute for attribute which can be set in an other
specific way.

objRef.className = "xxx";
will work in MSIE 6 for Windows, Opera 7, NS 7.x, Mozilla 1.x, K-meleon
0.8 and all other W3C DOM level 1 compliant browsers.

http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-95362176

Same thing with the disabled attribute.

http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-50886781
Any Help on these issues will be appreciated.

CES


function fDisableLable(){
for(var a = 0;a < document.forms.length;a++){
var fname = document.forms[a].name;
var f = document.forms[fname];

Why these 2 above instructions? Why not the simple, straightforward and
much more efficient (accessing forms' collection):

var currentForm = document.forms[a];
for(c = 0;c < f.length;c++){
var x = f.elements[c].id;
if(x!=""){
var v = f.elements[x].getAttribute("disabled")


Here's how I would do this:

for(var ElementIterator = 0; ElementIterator < currentForm.length;
ElementIterator++)
{
var currentFormElement = currentForm.elements[ElementIterator];
if ((currentFormElement.disabled) && (currentFormElement.type !=
"button") && (currentFormElement.type != "submit"))
{
currentFormElement.className = "dataLable_TextDisabled";
};
}

Not tested but I'm pretty sure this should work in all W3C DOM level 1
compliant browsers.

var t = f.elements[x].getAttribute("type")

//This is where I'm having the problem
if((v==true)&&(t!="button")&&(t!="submit")){
//ie version
document.getElementById(x +
'Lable').setAttribute("className", "dataLable_TextDisabled");
//netscape version
document.getElementById(x +
'Lable').setAttribute("class", "dataLable_TextDisabled");
}
}
}
}
}

One last coding recommendation. Absolutely avoid non-meaningful,
non-significant identifiers in your code. a, x, c, t, v in the absolute
(and even in the relative) mean nothing.. except letters.
Choosing non-intuitive, non-self-explanatory identifiers is bad for
debugging with softwares, it can not help you understand your code now
or later, it can not help others review your code, etc..

DU
 
C

CES

DU,
Thanks for the help...CES


DU said:
CES said:
All,
I'm at a loss, the code below works in IE but not in Netscape and I'm
unskilled enough not to know why.

Essentially this code looks thru all of the form fields and if the input box
has a attribute of disabled="true", attribute would only be present if the
field was disabled, then the label field's class is changed to a grayed out
color.

--- The first problem seems to be with the v==true statement, I've tried
every variation I can think of but v==true is the only one that works in IE.

--- The second problem is the way IE & Netscape/Opera uses different class
attribute statements, is their a way of using 1 setAttribute statement that
will work in IE and Netscape as apposed to:

setAttribute("className", "xxx") for IE
and
setAttribute("class", "xxx") for Netscape

Do not use setAttribute for attribute which can be set in an other
specific way.

objRef.className = "xxx";
will work in MSIE 6 for Windows, Opera 7, NS 7.x, Mozilla 1.x, K-meleon
0.8 and all other W3C DOM level 1 compliant browsers.

http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-95362176

Same thing with the disabled attribute.

http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-50886781
Any Help on these issues will be appreciated.

CES


function fDisableLable(){
for(var a = 0;a < document.forms.length;a++){
var fname = document.forms[a].name;
var f = document.forms[fname];

Why these 2 above instructions? Why not the simple, straightforward and
much more efficient (accessing forms' collection):

var currentForm = document.forms[a];
for(c = 0;c < f.length;c++){
var x = f.elements[c].id;
if(x!=""){
var v = f.elements[x].getAttribute("disabled")


Here's how I would do this:

for(var ElementIterator = 0; ElementIterator < currentForm.length;
ElementIterator++)
{
var currentFormElement = currentForm.elements[ElementIterator];
if ((currentFormElement.disabled) && (currentFormElement.type !=
"button") && (currentFormElement.type != "submit"))
{
currentFormElement.className = "dataLable_TextDisabled";
};
}

Not tested but I'm pretty sure this should work in all W3C DOM level 1
compliant browsers.

var t = f.elements[x].getAttribute("type")

//This is where I'm having the problem
if((v==true)&&(t!="button")&&(t!="submit")){
//ie version
document.getElementById(x +
'Lable').setAttribute("className", "dataLable_TextDisabled");
//netscape version
document.getElementById(x +
'Lable').setAttribute("class", "dataLable_TextDisabled");
}
}
}
}
}

One last coding recommendation. Absolutely avoid non-meaningful,
non-significant identifiers in your code. a, x, c, t, v in the absolute
(and even in the relative) mean nothing.. except letters.
Choosing non-intuitive, non-self-explanatory identifiers is bad for
debugging with softwares, it can not help you understand your code now
or later, it can not help others review your code, etc..

DU
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top