...

View Full Version : Effect Opening and Closing a Div



mercuryfrost
07-20-2010, 03:21 PM
Hi there all,

Trying to adapt a bit of Code, but failing wonderfully!

I'm writing in Cold Fusion, but using a little java script to create the sliding effect. It's from a sliding open list function in another site, and I tried to just hack my current needs in there.



<script>
function DC_ShowHideMoreWebsites(id) {
if( document.getElementById( "contentsections2").style.display=="none" ) {
Effect.BlindDown( "contentsections2");
return false;
} else {
Effect.SlideUp( "contentsections2" ); return false;
}
}
</script>

is followed by


<p id="moreScreenshots"><a href="#" onclick="DC_ShowHideMoreWebsites"; return false;">More Website Examples</a></p>

I've tested the script, div and the DB call by just calling it with


<p id="moreScreenshots"><a href="#" onclick="Effect.BlindDown('contentsections2'); return false;">More Website Examples</a></p>
And that works fine.

I've never coded in Java, hence the problem! any help appreciated

wildreason
07-20-2010, 03:34 PM
Are you getting any errors in Firefox's Error Console?

mercuryfrost
07-20-2010, 03:41 PM
Don't appear to be no.

Rowsdower!
07-20-2010, 08:44 PM
It will be a whole lot easier to get to the bottom of this if we can see your test page. Do you have this up anywhere we can get to it?

Old Pedant
07-21-2010, 03:45 AM
Makes no sense:


<p id="moreScreenshots"><a href="#" onclick="DC_ShowHideMoreWebsites"; return false;">More Website

(1) You have mismatched quote marks. Quotes *MUST* come in pairs.
(2) You are *NOT* calling a function. There are no parentheses after the function name there.

You declared the function as


function DC_ShowHideMoreWebsites(id) { ... }

meaning that you expect to be passed an id value when the function is invoked.

Yet the code in that function never uses the id at all, so why is it there?

So:


function DC_ShowHideMoreWebsites( ) /* no arguments needed */
{
... your code ...
}

And then


<p id="moreScreenshots"><a href="#" onclick="DC_ShowHideMoreWebsites(); return false;">More Website Examples</a></p>

mercuryfrost
07-21-2010, 11:38 AM
Many thanks for the advice all
Have it working now after spotting a few little errors


It was calling an id because the code I took it from had been on a loop.

There was the stray quote marks you told of.
The semi-colon was outside the quotes before the return false

After this the script was working, but jumping to the top of the page. So changed the href to javascript:;

Final code was as follows, and works like a dream, thanks for time all!


<script>
function DC_ShowHideMoreWebsites( ) {
if( document.getElementById( "contentsections2").style.display=="none" ) {
Effect.BlindDown( "contentsections2");
return false;
} else {
Effect.SlideUp( "contentsections2" ); return false;
}
}
</script>


<p id="moreScreenshots"><a href="javascript:;" onclick="DC_ShowHideMoreWebsites()" return false;>More Website Examples</a></p>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum