getAttribute("disabled") not working in Netscape

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • CES

    #1

    getAttribute("disabled") not working in Netscape

    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("c lassName", "xxx") for IE
    and
    setAttribute("c lass", "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.getEle mentById(x +
    'Lable').setAtt ribute("classNa me", "dataLable_Text Disabled");
    //netscape version
    document.getEle mentById(x +
    'Lable').setAtt ribute("class", "dataLable_Text Disabled");
    }
    }
    }
    }
    }


  • DU

    #2
    Re: getAttribute(&q uot;disabled&qu ot;) not working in Netscape

    CES wrote:[color=blue]
    > 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("c lassName", "xxx") for IE
    > and
    > setAttribute("c lass", "xxx") for Netscape[/color]

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

    objRef.classNam e = "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
    [color=blue]
    >
    > 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];[/color]

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

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


    Here's how I would do this:

    for(var ElementIterator = 0; ElementIterator < currentForm.len gth;
    ElementIterator ++)
    {
    var currentFormElem ent = currentForm.ele ments[ElementIterator];
    if ((currentFormEl ement.disabled) && (currentFormEle ment.type !=
    "button") && (currentFormEle ment.type != "submit"))
    {
    currentFormElem ent.className = "dataLable_Text Disabled";
    };
    }

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

    [color=blue]
    > 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.getEle mentById(x +
    > 'Lable').setAtt ribute("classNa me", "dataLable_Text Disabled");
    > //netscape version
    > document.getEle mentById(x +
    > 'Lable').setAtt ribute("class", "dataLable_Text Disabled");
    > }
    > }
    > }
    > }
    > }
    >
    >[/color]

    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

    Comment

    • CES

      #3
      Re: getAttribute(&q uot;disabled&qu ot;) not working in Netscape

      DU,
      Thanks for the help...CES


      "DU" <drunclear@hotW IPETHISmail.com > wrote in message
      news:bq74u8$g7a $1@news.eusc.in ter.net...[color=blue]
      > CES wrote:[color=green]
      > > 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[/color][/color]
      box[color=blue][color=green]
      > > has a attribute of disabled="true" , attribute would only be present if[/color][/color]
      the[color=blue][color=green]
      > > field was disabled, then the label field's class is changed to a grayed[/color][/color]
      out[color=blue][color=green]
      > > 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[/color][/color]
      IE.[color=blue][color=green]
      > >
      > > --- The second problem is the way IE & Netscape/Opera uses different[/color][/color]
      class[color=blue][color=green]
      > > attribute statements, is their a way of using 1 setAttribute statement[/color][/color]
      that[color=blue][color=green]
      > > will work in IE and Netscape as apposed to:
      > >
      > > setAttribute("c lassName", "xxx") for IE
      > > and
      > > setAttribute("c lass", "xxx") for Netscape[/color]
      >
      > Do not use setAttribute for attribute which can be set in an other
      > specific way.
      >
      > objRef.classNam e = "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
      >[color=green]
      > >
      > > 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];[/color]
      >
      > Why these 2 above instructions? Why not the simple, straightforward and
      > much more efficient (accessing forms' collection):
      >
      > var currentForm = document.forms[a];
      >[color=green]
      > > for(c = 0;c < f.length;c++){
      > > var x = f.elements[c].id;
      > > if(x!=""){
      > > var v = f.elements[x].getAttribute(" disabled")[/color]
      >
      >
      > Here's how I would do this:
      >
      > for(var ElementIterator = 0; ElementIterator < currentForm.len gth;
      > ElementIterator ++)
      > {
      > var currentFormElem ent = currentForm.ele ments[ElementIterator];
      > if ((currentFormEl ement.disabled) && (currentFormEle ment.type !=
      > "button") && (currentFormEle ment.type != "submit"))
      > {
      > currentFormElem ent.className = "dataLable_Text Disabled";
      > };
      > }
      >
      > Not tested but I'm pretty sure this should work in all W3C DOM level 1
      > compliant browsers.
      >
      >[color=green]
      > > 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.getEle mentById(x +
      > > 'Lable').setAtt ribute("classNa me", "dataLable_Text Disabled");
      > > //netscape version
      > > document.getEle mentById(x +
      > > 'Lable').setAtt ribute("class", "dataLable_Text Disabled");
      > > }
      > > }
      > > }
      > > }
      > > }
      > >
      > >[/color]
      >
      > 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
      >[/color]


      Comment

      Working...