Current location: Hot Scripts Forums » General Web Coding » JavaScript » badly help needed / div hide/show


badly help needed / div hide/show

Reply
  #1 (permalink)  
Old 03-29-06, 09:01 PM
dsmportal dsmportal is offline
Newbie Coder
 
Join Date: Mar 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Angry badly help needed / div hide/show

i have some html code with div and i want to hide/show as the user click :
Code:
<div class='section_divider'> 
                <table width='100%' border='0' cellpadding='0' cellspacing='0'>
                <tr>
                <td class='section_title' style='width: 363px'>" + this.XPandoTitle + "</td>          
                <td class='section_updatedby'>" + DateTime.Now + "</td>
                <td class='section_expand'><img  onclick= expandcontent('"+ this.XPandoID + "'); style='WIDTH:100%;cursor:hand; cursor:pointer' alt='collopse' src='Images/section_collapse_off.gif' width='29' height='29'/></td>
                </tr>
                </table>
                </div>

                <div id='" + this.XPandoID + "'class='switchcontent'>     
                <table width='70%' border='0' cellpadding='0' cellspacing='0' class='menutable_outline'>     
                <tr>
           
                </tr>    
                </table>   
                </div>
i want some javascript to hide/show the div
onclick= expandcontent
....

Last edited by TwoD; 03-30-06 at 02:16 AM. Reason: Please use [code][/code] wrappers.
Reply With Quote
  #2 (permalink)  
Old 03-30-06, 01:34 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Add this to the div:

Code:
style="display:none"
So it should look like this more or less:

Code:
<div id="whatever" style="display:none">Some content here...</div>

Place this somewhere in the head or wherever:

Code:
<script type="text/javascript">

function Visibility(id)
{
	if (document.getElementById(id).style.display == 'none')
	{
		document.getElementById(id).style.display = 'block';
	}
	else
	{
		document.getElementById(id).style.display = 'none';
	}
}

</script>
And create a link like this, with the correct div id

Code:
<a href="#" onClick="Visibility('whatever');">Show div, hide div</a>

Hope this helps!
Reply With Quote
  #3 (permalink)  
Old 03-30-06, 08:02 AM
dsmportal dsmportal is offline
Newbie Coder
 
Join Date: Mar 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
sorry to say it does not work...

here is my complete code for your reference:
Code:
//html

 <div class='section_divider'> 
                <table width='100%' border='0' cellpadding='0' cellspacing='0'>
                <tr>
                <td class='section_title' style='width: 363px'>this.XPandoTitle</td>          
                <td class='section_updatedby'> DateTime.Now</td>
                <td class='section_expand'><img  onclick="expandContent('XPandoID');" style='WIDTH:100%;cursor:hand; cursor:pointer' alt='collopse' src='Images/section_collapse_off.gif' width='29' height='29'/></td>
                </tr>
                </table>
                             <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                             <asp:Button ID="Button1" runat="server" Text="Button" /></div>

 
                <div id='XPandoID' style="display:none" class='switchcontent'>     
                <table width='70%' border='0' cellpadding='0' cellspacing='0' class='menutable_outline'>     
                <tr>
           
                </tr>    
                </table>   
                </div>   



/js

function expandContent(id)
{
alert(id);
 

	if (document.getElementById(id).style.display == 'none')
	{
		document.getElementById(id).style.display = 'block';
	}
	else
	{
		document.getElementById(id).style.display = 'none';
	}
}

Last edited by TwoD; 03-30-06 at 06:56 PM. Reason: Please use [code][/code] wrappers!
Reply With Quote
  #4 (permalink)  
Old 03-30-06, 08:14 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
It does work for me. You just don't have any content to show up in the div (except an empty table).

Code:
<script type="text/javascript">

function expandContent(id)
{
	if (document.getElementById(id).style.display == 'none')
	{
		document.getElementById(id).style.display = 'block';
	}
	else
	{
		document.getElementById(id).style.display = 'none';
	}
}

</script>

<div class='section_divider'>
<table width='100%' border='0' cellpadding='0' cellspacing='0'>
<tr>
<td class='section_title' style='width: 363px'>this.XPandoTitle</td>
<td class='section_updatedby'> DateTime.Now</td>
<td class='section_expand'><img onclick="expandContent('XPandoID');" style='WIDTH:100%;cursor:hand; cursorointer' alt='collopse' src='Images/section_collapse_off.gif' width='29' height='29'/></td>
</tr>
</table>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" /></div>


<div id='XPandoID' style="display:none" class='switchcontent'>
<table width='70%' border='0' cellpadding='0' cellspacing='0' class='menutable_outline'>
<tr>
<td>Test content here.... </td>
</tr>
</table>
</div>
Reply With Quote
  #5 (permalink)  
Old 03-30-06, 09:04 AM
dsmportal dsmportal is offline
Newbie Coder
 
Join Date: Mar 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
here is what im trying to do..
Code:
//
 protected override void RenderContents(HtmlTextWriter o)
        {
        
        StringBuilder sb = new StringBuilder();
        
            
            sb.Append("  <div class='section_divider'> ");
            sb.Append("    <table width='100%' border='0' cellpadding='0' cellspacing='0'>");
            sb.Append("    <tr>");
            sb.Append("    <td class='section_title' style='width: 363px'>" + this.XPandoTitle + "</td>          ");
            sb.Append("    <td class='section_updatedby'>" + DateTime.Now + "</td>");
            sb.Append("    <td class='section_expand'><img  onclick= expandContent('"+ this.XPandoID + "'); style='WIDTH:100%;cursor:hand; cursor:pointer' alt='collopse' src='Images/section_collapse_off.gif' width='29' height='29'/></td>");
           
            sb.Append("    </tr>");
            sb.Append("    </table>");
            sb.Append("    </div>");

            sb.Append("    <div id='" + this.XPandoID + "'class='switchcontent'>     ");
            sb.Append("    <table width='70%' border='0' cellpadding='0' cellspacing='0' class='menutable_outline'>     ");
            sb.Append("    <tr>");
            sb.Append("    <td>adfasdf             asdfasdf             asdfasd     a   </td>");
            sb.Append("    </tr>    ");
            sb.Append("    </table>   ");
            sb.Append("    </div>   ");

            o.Write(sb.ToString());
Please use [code ][/code ] wrappers, they are there to help keeping the code readable! Once, ok. But thrice in the same thread... - TwoD

Last edited by TwoD; 03-30-06 at 06:59 PM. Reason: Please use [code][/code] wrappers!
Reply With Quote
  #6 (permalink)  
Old 03-30-06, 09:13 AM
dsmportal dsmportal is offline
Newbie Coder
 
Join Date: Mar 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
i debug when i click very very first time im getting the value = 'none'

document.getElementById(id).style.display

none

and it disappear the whole div
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
expanding a div to keep image contained pukington HTML/XHTML/XML 0 12-26-05 08:04 AM
CSS Div problem themanmathias CSS 1 09-29-05 08:05 PM
Help badly needed!! Urgent!! hugo84 ASP 1 08-28-05 02:15 PM
Database help! (needed badly) sammysmee PHP 2 05-26-05 04:54 AM
Change width of div if another div is not present hockeykid JavaScript 2 12-08-04 07:27 PM


All times are GMT -5. The time now is 11:05 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.