Results 1 to 2 of 2

Thread: show a div having style="display:none" when get value to the js variable

  1. #1
    Join Date
    Sep 2010
    Posts
    9

    Question show a div having style="display:none" when get value to the js variable

    Initially the div id =" showHide" is invisible. I want to make it visible when the value of vall is not null. But the code is not working. Though variable vall is getting values, the div is still not visible. What is the problem with js codescript?? How to solve this problem??
    Code:
    <head>
    
    <script language="javascript">
    
        var vall = "<%=vall%>";
    
        <% System.out.println("jsvar="+vall);%>
    	/* vall is getting the values*/
    
        if (vall != null)
            {
                mydiv = document.getElementById("showHide");
                mydiv.style.visibility = "visible";
    
            }
        </script>
    </head>
    
    <body>
    <div id =" showHide" style="display:none">
            
    	/*HTML TABLE*/
    </div>
    
    </body>

  2. #2
    Join Date
    Aug 2009
    Location
    Texas
    Posts
    193
    The following works for me:

    Code:
    document.getElementById('showHide').setAttribute('style', 'display: block;');
    Although there are compatibility issues with some versions of IE. I think in IE you can do:

    Code:
    document.getElementById('showHide').style.cssText = 'display: block;';

Similar Threads

  1. "this" operator error or "style.left" error not sure
    By gman1103 in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 1
    Last Post: 26 Feb 2009, 08:53 AM

Tags for this Thread

Posting Permissions

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