Web Form Javascript to hide a div not workinghttp://forums.asp.net/t/1772141.aspx/1?Web+Form+Javascript+to+hide+a+div+not+workingTue, 21 Feb 2012 16:15:49 -050017721414843431http://forums.asp.net/p/1772141/4843431.aspx/1?Web+Form+Javascript+to+hide+a+div+not+workingWeb Form Javascript to hide a div not working <p>I am creating the contacts page of a website and want the div element &quot;contact-area&quot; to hide after they click the &quot;submit button&quot; and a successful email has been sent. The Javascript function to hide a Div element:</p> <pre class="lang-cs prettyprint"><pre class="prettyprint">function hideDiv(){ document.getElementbyId(contact-area).style.visible=&quot;hidden&quot;; }</pre></pre> <p>The code is called by using "OnClientClick" in the button element:</p> <pre class="lang-cs prettyprint"><pre class="prettyprint"><span class="pun">&lt;</span><span class="pln">asp</span><span class="pun">:</span><span class="typ">Button</span><span class="pln"> ID</span><span class="pun">=</span><span class="str">"submitbutton"</span><span class="pln"> runat</span><span class="pun">=</span><span class="str">"server"</span><span class="pln"> </span><span class="typ">Text</span><span class="pun">=</span><span class="str">"Submit"</span><span class="pln"> OnClientClick</span><span class="pun">=</span><span class="str">"hideDiv();"</span><span class="pln"> </span><span class="pun">/&gt;</span><span class="pln"><br /></span></pre></pre> <p></p> <p>When I click the submit button nothing happens. There is no compile errors, is there something I am missing here??</p></pre> 2012-02-21T15:31:58-05:004843435http://forums.asp.net/p/1772141/4843435.aspx/1?Re+Web+Form+Javascript+to+hide+a+div+not+workingRe: Web Form Javascript to hide a div not working <p>I think you just need to put double-quotes areound contact-area like document.getElementbyId(&quot;<span class="pln"><span class="pln">contact</span></span><span class="pun"><span class="pun">-</span></span><span class="pln"><span class="pln">area&quot;).style.visible=&quot;hidden&quot;;</span></span></p> 2012-02-21T15:35:09-05:004843439http://forums.asp.net/p/1772141/4843439.aspx/1?Re+Web+Form+Javascript+to+hide+a+div+not+workingRe: Web Form Javascript to hide a div not working <p>does the page refreshes (post back) after button click? if yes, then hiding div in javascript would not help...</p> <p>rather you should hide it in button click server event.... like this</p> <p>content-area.Visible = false;</p> <p>if it is not posting back on button click, then u can hide div on client side.... but the function should be changed as</p> <p>function hideDiv(){&nbsp;&nbsp;&nbsp; <br> &nbsp; document.getElementbyId(contact-area<strong>).style.display=&quot;none&quot;;</strong><br> &nbsp; return false;<br> }</p> <p>and the button tag should look like</p> <p>&lt;asp:Button ID=&quot;submitbutton&quot; runat=&quot;server&quot; Text=&quot;Submit&quot; OnClientClick=&quot;<strong>return</strong> hideDiv();&quot; /&gt;</p> <p>hope this helps...&nbsp;</p> 2012-02-21T15:37:22-05:004843441http://forums.asp.net/p/1772141/4843441.aspx/1?Re+Web+Form+Javascript+to+hide+a+div+not+workingRe: Web Form Javascript to hide a div not working Put contact-area inside quotes: getElementById('contact-area') 2012-02-21T15:37:58-05:004843443http://forums.asp.net/p/1772141/4843443.aspx/1?Re+Web+Form+Javascript+to+hide+a+div+not+workingRe: Web Form Javascript to hide a div not working <p>Nope, doesn't work either, Ive already tried double and single quotes. No luck though.</p> 2012-02-21T15:39:06-05:004843461http://forums.asp.net/p/1772141/4843461.aspx/1?Re+Web+Form+Javascript+to+hide+a+div+not+workingRe: Web Form Javascript to hide a div not working Another issue is the postback as mentioned previously. You can stop the postback using: OnClientClick=&quot;hideDiv();return false;&quot;. 2012-02-21T15:45:32-05:004843469http://forums.asp.net/p/1772141/4843469.aspx/1?Re+Web+Form+Javascript+to+hide+a+div+not+workingRe: Web Form Javascript to hide a div not working <p>It must use post-back as it refreshes the page, so yes Javascript would not help here then. I thought it was best to use code in the c# file, but I wasn't sure if I could manipulate dom elements from here so I decided to use JavaScript. Originally i had &lt;&nbsp;content-area.Visible = false; &gt; but it does not recognise &quot;content-area&quot;, i get 2 errors:</p> <p>The name &quot;contact&quot; does not exist in the current context</p> <p>The name &quot;area&quot; does not exist in the current context</p> 2012-02-21T15:49:46-05:004843479http://forums.asp.net/p/1772141/4843479.aspx/1?Re+Web+Form+Javascript+to+hide+a+div+not+workingRe: Web Form Javascript to hide a div not working <p>That stops the postback, but the div still isnt hiding.</p> 2012-02-21T15:53:03-05:004843481http://forums.asp.net/p/1772141/4843481.aspx/1?Re+Web+Form+Javascript+to+hide+a+div+not+workingRe: Web Form Javascript to hide a div not working Instead of a div use an asp:panel control. It renders as a div but youll have access to it BL is code. You can then show/hide it from code via it's ID. 2012-02-21T15:55:32-05:004843504http://forums.asp.net/p/1772141/4843504.aspx/1?Re+Web+Form+Javascript+to+hide+a+div+not+workingRe: Web Form Javascript to hide a div not working <p>hi</p> <p>chang u r div id=<span class="pln">contact</span><span class="pln">area</span></p> <p>check it</p> <p><span>document.getElementById('</span><strong><span class="pln">contact</span></strong><span class="pln"><strong>area</strong>').style.visibility = <strong>'hidden'</strong>;</span></p> <p><span class="pln">or,</span></p> <p><span class="pln">try this way</span></p> <p><span class="pln"><a href="http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/">http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/</a></span></p> <p><span class="pln">thank u</span></p> 2012-02-21T16:09:27-05:004843518http://forums.asp.net/p/1772141/4843518.aspx/1?Re+Web+Form+Javascript+to+hide+a+div+not+workingRe: Web Form Javascript to hide a div not working <p>okay..this one working for me -&nbsp;</p> <pre class="prettyprint">&lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; CodeFile=&quot;Default.aspx.cs&quot; Inherits=&quot;_Default&quot; %&gt; &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt; &lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt; &lt;head id=&quot;Head1&quot; runat=&quot;server&quot;&gt; &lt;title&gt;Untitled Page&lt;/title&gt; &lt;script type=&quot;text/javascript&quot;&gt; function call() { var ca = document.getElementById('abc'); ca.style.display = 'none'; return false; } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt; &lt;div&gt; &lt;div id=&quot;abc&quot; name=&quot;div1&quot;&gt;This is Rami&lt;/div&gt; &lt;asp:Button ID=&quot;Button1&quot; runat=&quot;server&quot; Text=&quot;Button&quot; OnClientClick=&quot;return call()&quot; /&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt;</pre> 2012-02-21T16:15:49-05:00