Web Design Forum  
 
Go Back   Web Design Forum > Web and Graphic Design > Web Design

Reply
 
LinkBack Thread Tools Display Modes
Old 03-16-2011, 06:42 PM   #1
New Member
 
Join Date: Mar 2011
Posts: 4
Default HTML Toggle function



Hello! I'm trying to make a Toggle function work on a website to hide/show text after click, but it's working the other way around: it shows the text and when you click it hides it, I want for it to be hidden and then show it! Anyone has any suggestions?

Here's the link so you can see it, scroll to "All You Can Learn Pass" and see it:

http://www.vlany.org/index.php#event

And here's the code I have:

<script type="text/javascript">
function WM_toggle(id){
var x = document.getElementById(id);
var display = "";
if (x.style.display == "none") {
display = "";
} else {
display = "none";
}
x.style.display = display;
}
</script>

<h1><a href="#event" onClick="WM_toggle('eventAYCLP'); return true" >
VLA's All You Can Learn Pass</a>
</h1>
<dd id="eventAYCLP">
<? require("dropdownmenus/descriptions/descrip_ayclp.php"); ?>
</dd>
<tr id="eventAYCLP" style="display:none">
</tr><hr />


THANKS!!

L

nietodickens is offline   Reply With Quote


Old 03-16-2011, 08:30 PM   #2
Gold Member
 
Join Date: Feb 2011
Location: Australia
Posts: 369
Default

You are missing the semi-colon after the display:none

Code:
<tr id="eventAYCLP" style="display:none;">
Hope that helps
DHDdirect is offline   Reply With Quote
Old 03-16-2011, 09:28 PM   #3
New Member
 
Join Date: Mar 2011
Posts: 4
Default

thanks for your response DHDdirect!

unfortunately it didn't work at all, don't know why, it seems that there's something that has to trigger the toggle function when the page uploads, but I have no idea how to! couldn't find it online anywhere.

I will keep trying to find something

thanks for the help!
nietodickens is offline   Reply With Quote
Old 03-16-2011, 09:33 PM   #4
Gold Member
 
Join Date: Feb 2011
Location: Australia
Posts: 369
Default

Can you provide the rest of the html code? Something doesn't look correct with the Javascript as well so it'll help if you can provide the whole picture. Either post it here or a link.

Try this and see if it helps:

Code:
<script type="text/javascript">
function WM_toggle(id){
var x = document.getElementById(id).style;
if (x.display == "none") {
x.display = "block";
} else {
x.display = "none";
}
}
</script>

Last edited by DHDdirect; 03-16-2011 at 09:38 PM.
DHDdirect is offline   Reply With Quote
Old 03-17-2011, 05:50 PM   #5
New Member
 
Join Date: Mar 2011
Posts: 4
Default

DHD

here's the link to the website:

http://www.vlany.org/index.php

Scroll down to the title: "All You Can Learn Pass" to see it work the other way around how I wanted to work.

Let me know if you can see it.

Thanks!
nietodickens is offline   Reply With Quote


Old 03-17-2011, 08:50 PM   #6
Gold Member
 
Join Date: Feb 2011
Location: Australia
Posts: 369
Default

Of course.. because it's not the <tr> element you are trying to hide because there is nothing in it as it is. So you can move the style="display:none;" up to the <dd> element

Code:
<dd id="eventAYCLP" style="display:none;">
__________________
Jason H.
DHDdirect.com
Domains - Hosting - Design

Last edited by DHDdirect; 03-17-2011 at 10:45 PM.
DHDdirect is offline   Reply With Quote
Old 03-17-2011, 09:45 PM   #7
New Member
 
Join Date: Mar 2011
Posts: 4
Default Awesome!

It worked like a charm! So simple yet so hard to notice for a novice in HTML like me. Thanks so much DHDdirect! You ROCK!


nietodickens is offline   Reply With Quote
Old 03-22-2011, 05:20 PM   #8
Super Moderator
 
Join Date: Oct 2008
Location: Arizona, USA
Posts: 1,053
Default

I would use jquery, much less hassle. they have a .toggle(), .hide(), .show(), among many others. Good to see you got it working though.
__________________
John Darling
Graphic / Web Designer
SmarterTools Inc.
(877) 357-6278
www.smartertools.com
PixelPusher is offline   Reply With Quote
Reply

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 06:53 PM.


Camera Forum - Computer Forum - Web Design Forum

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Content Relevant URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.