Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > getAttribute("disabled") not working in Netscape

Reply
Thread Tools

getAttribute("disabled") not working in Netscape

 
 
CES
Guest
Posts: n/a
 
      11-28-2003
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");
}
}
}
}
}


 
Reply With Quote
 
 
 
 
DU
Guest
Posts: n/a
 
      11-28-2003
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

 
Reply With Quote
 
 
 
 
CES
Guest
Posts: n/a
 
      11-29-2003
DU,
Thanks for the help...CES


"DU" <(E-Mail Removed)> wrote in message
news:bq74u8$g7a$(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Netscape 7.1 to Netscape 8 Skid Schermerhorn Firefox 2 09-05-2005 04:04 PM
Accessing Netscape mail via Netscape mail client A. Toprak Computer Support 0 12-24-2004 06:46 AM
Netscape with JRE 1.5 beta 1 ignores Netscape signing Mickey Segal Java 1 05-21-2004 01:52 PM
Script is working in IE, but not working in Netscape 7 - trouble with document.selection.createRange(); lawrence Javascript 8 05-05-2004 01:43 AM
websphere, oracle, netscape: netscape timeout Tom Java 0 08-01-2003 11:03 PM



Advertisments