getAttribute("disabled") not working in Netscape

Discussion in 'Javascript' started by CES, Nov 28, 2003.

  1. CES

    CES Guest

    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");
    }
    }
    }
    }
    }
     
    CES, Nov 28, 2003
    #1
    1. Advertising

  2. CES

    DU Guest

    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-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
     
    DU, Nov 28, 2003
    #2
    1. Advertising

  3. CES

    CES Guest

    DU,
    Thanks for the help...CES


    "DU" <> wrote in message
    news:bq74u8$g7a$...
    > 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-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
    >
     
    CES, Nov 29, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DN
    Replies:
    2
    Views:
    11,859
  2. lawrence
    Replies:
    8
    Views:
    264
    lawrence
    May 5, 2004
  3. Saravanan K
    Replies:
    2
    Views:
    114
    Grant Wagner
    Nov 19, 2004
  4. Gautam

    'disabled' property in Netscape

    Gautam, Jan 7, 2005, in forum: Javascript
    Replies:
    3
    Views:
    102
    Grant Wagner
    Jan 10, 2005
  5. Steve
    Replies:
    4
    Views:
    300
    Steve
    Oct 13, 2007
Loading...

Share This Page