Please login or register. Welcome to the Studio, guest!


Quick Links:


newBookmarkLockedFalling

Andrew McGivery

Andrew McGivery Avatar
Formerly Fredy

******
Legendary Studio Member

Male
5,742


September 2005
First, heres the main script that does all the work :P


<script>
var ie5 = document.all && document.getElementById;
var ns6 = document.getElementById && !document.all;

function showMore(whichid) {
if (ie5||ns6) { var showid = document.getElementById(whichid); }
if (showid.style.display == 'none') {
showid.style.display = '';
} else {
showid.style.display='none';
}
}
</script>


next, you need to put a hide/show link.

example:

<a href="javascript:showMore('View');">View</a>


next the div that will show or hide:

example:


<div id="View" style="display: none;">

ROAR! :o

</div>


Comes in handy... well at least it has to me :P

enjoy.

k

Scorpian

Scorpian Avatar

******
[ Bracket Admin ]

2,457


April 2006
Very useful indeed, however you can simplify the ShowMore() function a little

function showMore(whichid) {
if (ie5||ns6) { var showid = document.getElementById(whichid); }
if (showid.style.display == 'none') {
showid.style.display = '';
} else {
showid.style.display='none';
}
}


You can use a one-line conditional instead of an if/then/else statement. Observe...

function showMore(whichid) {
if (ie5||ns6) { var showid = document.getElementById(whichid); }
showid.style.display = (show.id.style.display == 'none') ? '' : 'none';
}


That states that if showid's style is equal to not be shown, allow it to be shown.
wat

Chris

Chris Avatar

******
Head Coder

19,519


June 2005
Simplify it further. Do we need to know if its ie5 or ns6? No. It just has to support "document.getElementById"

<script type="text/Javascript">
function showMore(whichid) {
if(!document.getElementById)
return false;
var showid = document.getElementById(whichid);
showid.style.display = (showid.style.display == "none"?"":"none");
}
</script>


Personally, I'd find it easier to pass the element to be changed to the function via a parameter.

<script type="text/Javascript">
function showMore(ext){
if(ext)
ext.style.display = (ext.style.display == "none"?"":"none");
}
</script>


Just my two cents. Also, its good considering you're still learning. ;)

Xylish

Xylish Avatar

******
Ghost Admin

1,895


June 2005
Good and simple script for a newbie coder like me ;)
Ex-admin, designer and founder of Studio Zero. Currently working as a Dentist :)

Andrew McGivery

Andrew McGivery Avatar
Formerly Fredy

******
Legendary Studio Member

Male
5,742


September 2005
popojoe said:
Good and simple script for a newbie coder like me ;)


thats what i said! :P
k

newBookmarkLockedFalling