By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,842 Members | 2,368 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,842 IT Pros & Developers. It's quick & easy.

getAttribute("disabled") not working in Netscape

P: n/a
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");
}
}
}
}
}
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
DU
CES wrote:
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-HTM...ml#ID-95362176

Same thing with the disabled attribute.

http://www.w3.org/TR/DOM-Level-2-HTM...ml#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

Jul 20 '05 #2

P: n/a
CES
DU,
Thanks for the help...CES
"DU" <dr*******@hotWIPETHISmail.com> wrote in message
news:bq**********@news.eusc.inter.net...
CES wrote:
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-HTM...ml#ID-95362176

Same thing with the disabled attribute.

http://www.w3.org/TR/DOM-Level-2-HTM...ml#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

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.