News:

The "Support Requests" forum is now viewable by guests.

Main Menu

Java script link thingy

Started by Evilsprouts, May 08, 2006, 08:35:39 PM

Previous topic - Next topic

Evilsprouts

Umm I have a page which I have a comments bit that goes at the bottom however the page looks too crowded with the comments bit at the bottom so what I want to do is have a link on the page and when the user click it the comment bit is displayed at the bottom. So basically you click the link it displays you click the link again it goes.

Any ideas please????

Thanks!  :)

dest

Put the comments in a div, resize the div on click. 
meh :P

Evilsprouts

How would I go about doing that please? I had a go but it didn't work :(

brainiac744

You can use a nice little snippet of code I just found here:

http://www.webmasterworld.com/forum91/441.htm

Evilsprouts

That's cool thanks but how would I make it so that when you click the link it shows the content then when you click it again it hides the content please?

Hers the code I'm using:

<script language=javascript type='text/javascript'>
function hideDiv() {
if (document.getElementById) {
document.getElementById('comments').style.visibility = 'hidden';
}
else {
if (document.layers) {
document.hideShow.visibility = 'hidden';
}
else {
document.all.hideShow.style.visibility = 'hidden';
}
}
}

function showDiv() {
if (document.getElementById) {
document.getElementById('comments').style.visibility = 'visible';
}
else {
if (document.layers) {
document.hideShow.visibility = 'visible';
}
else {
document.all.hideShow.style.visibility = 'visible';
}
}
}
</script>


Thanks

dest

Perhaps add a variable that gets set to different values (true/false, for example) by the two functions, and call a third function that checks the variable and runs show or hide depending on the value.
meh :P

Guide

Why don't you regroup the two functions in one, toggleDiv, which would first check whether the div is visible or not, and then either show or hide it ?

Something like :


function toggleDiv() {
if(document.getElementById('comments').style.visibility == 'hidden') {
     document.getElementById('comments').style.visibility = 'visible';
}
else {
     document.getElementById('comments').style.visibility = 'hidden';
}
}

Evilsprouts

Ahh thats great thank you very much.