JavaScript Style.display not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dgourd
    New Member
    • Apr 2010
    • 25

    JavaScript Style.display not working

    I cant get the style.display property to work properly. I have this test html page:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Test Javascript</title>
        
        <script language="javascript" type="text/javascript">
            window.onload = function () {
                document.getElementById("button").onclick = function () {
                    var text = document.getElementByName("username");
                    var loader = document.getElementById("ajax_laoder");
                    if (loader.style.display == "none") {
                        text.style.display = "none";
                        loader.style.display = "inline";
                    } else {
                        text.style.display = "inline";
                        loader.style.display = "none";
                    }
                }
            }
        </script>
    
    </head>
    
    <body>
    
    <input type="text" name="username" value="Username" class="loginfield" maxlength="60" /><br />
    <img src="images/ajax-loader.gif" alt="AJAX Loading" id="ajax_loader" style="display:none" /><br />
    <input type="submit" id="button" value="replace" title="Replace" />
    Basically, this has a textbox and a hidden gif, and a button called replace. When I click replace, the javascript doesnt do anything.
  • drhowarddrfine
    Recognized Expert Expert
    • Sep 2006
    • 7434

    #2
    I believe it's getElementsByNa me with an 's' which means it will return an array and not just text.

    Comment

    • dgourd
      New Member
      • Apr 2010
      • 25

      #3
      Wow. I completely looked that one over. Thanks a lot dude.

      Comment

      Working...