Results 1 to 7 of 7

Thread: JavaScript: Setting the disabled Flag

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140

    JavaScript: Setting the disabled Flag

    I'm trying to set the disabled flag on a input element. If you know of an easier way, please. Othwise, what is wrong with this?

    Code:
    <html>
      <head>
        <title>Test Page</title>
        <script type="text/javascript">
          function foo() {
            alert(document.getElementByID("myInput").nodeName);
          }
        </script>
      </head>
      <body>
        <form name="myForm">
          <input id="myInput" type="text" size="8" value="2">
        </form>
        <p onclick="javascript:foo();">Click Me</p>
      </body>
    </html>
    I can't get it to return nodeName, much less can I try to setAttributeNode, which may not even be what I need to do.
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  2. #2
    Fanatic Member punkpie_uk's Avatar
    Join Date
    Sep 2001
    Location
    UK
    Posts
    645
    Hi,

    I changed D in ID to lowercase it I got it work in IE...

    Code:
    alert(document.getElementById("myInput").nodeName);
    ... whats the problem you are having?

    I know it may be a stupid question but have you tried using style.disabled?

    Code:
    document.getElementById("myInput").style.disabled=true;
    SPREAD THE WORD!!! Are You Lee McCormick? Because I Am



    Lee M McCormick
    [email protected]

    Lee McCormick.com - Live
    Dynamically Webbed.com - In development but live

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    Oh forget it.

    Code:
    <html>
      <head>
        <title>Test Page</title>
        <script type="text/javascript">
          function enableBox() {
            document.getElementById("myInput").disabled = false;
          }
          function disableBox() {
            document.getElementById("myInput").disabled = true;
          }
          function foo() {
            alert(document.getElementById("myInput").nodeName);
          }
        </script>
      </head>
      <body>
        <form name="myForm">
          <p>Disabled:  <input type="text" size="8" disabled></p>
          <p><input id="myInput" name="myInput" type="text" size="8" value="2"></p>
          <p><input name="myRadio" type="radio" onclick="javascript:enableBox();">Enable</p>
          <p><input name="myRadio" type="radio" onclick="javascript:disableBox();">Disable</p>
          <p><input name="myButton" type="button" onclick="javascript:foo();" value="Click"></p>
        </form>
      </body>
    </html>
    .disabled works, though I don't find it in the documentation. I find .nodeName in the documentation, but it doesn't work in Opera. I'll get over it, that is Opera's fault.

    .style.disabled I think is meant to disable the style attribute, not the element itself.
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  4. #4
    Fanatic Member punkpie_uk's Avatar
    Join Date
    Sep 2001
    Location
    UK
    Posts
    645
    .style.disabled I think is meant to disable the style attribute, not the element itself.
    Whoops, I meant disabled on its own, i'm used to putting style if front because I work with CSS a lot.

    I cant find any decent documentation on it disabled either, I just guessed it would be this as disabled is an attribute for the input tag.
    SPREAD THE WORD!!! Are You Lee McCormick? Because I Am



    Lee M McCormick
    [email protected]

    Lee McCormick.com - Live
    Dynamically Webbed.com - In development but live

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    Well, if it isn't documented as part of the standard, I don't want to use it. If it blows up in a browser, it is my fault.
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  6. #6
    Fanatic Member punkpie_uk's Avatar
    Join Date
    Sep 2001
    Location
    UK
    Posts
    645
    I searched and I found it as part of the HTML4.01 standard at W3.org

    http://www.w3.org/TR/html401/interac...#adef-disabled

    It also does mention that you can dynamically change it using a script so I think you should be ok.
    SPREAD THE WORD!!! Are You Lee McCormick? Because I Am



    Lee M McCormick
    [email protected]

    Lee McCormick.com - Live
    Dynamically Webbed.com - In development but live

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    Yeah, I just don't know if I can say NodeObj.disabled, or if I'm supposed to say NodeObj.setAttribute("disabled") or something like that.
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width