View Full Version : Linking to external JS Not Working??

09-25-2008, 10:21 PM
Hi Guys

I know very little Javascript but have found a script I would like to use from Dhtml goodies website. Basically it expands boxes to show content. I like the idea, but I don't want the big chunk of code on my web page, and would rather link to an external file.

Could anybody see if this is possible for this code.

Here is the code:

// JavaScript Slide Code
/**************************************************************************************************** ********
(C) www.dhtmlgoodies.com, November 2005
**************************************************************************************************** ********/

var dhtmlgoodies_slideSpeed = 10; // Higher value = faster
var dhtmlgoodies_timer = 10; // Lower value = faster

var objectIdToSlideDown = false;
var dhtmlgoodies_activeId = false;
var dhtmlgoodies_slideInProgress = false;
function showHideContent(e,inputId)
dhtmlgoodies_slideInProgress = true;
if(!inputId)inputId = this.id;
inputId = inputId + '';
var numericId = inputId.replace(/[^0-9]/g,'');
var answerDiv = document.getElementById('dhtmlgoodies_a' + numericId);

objectIdToSlideDown = false;

if(!answerDiv.style.display || answerDiv.style.display=='none'){
if(dhtmlgoodies_activeId && dhtmlgoodies_activeId!=numericId){
objectIdToSlideDown = numericId;

answerDiv.style.visibility = 'visible';

dhtmlgoodies_activeId = false;

function slideContent(inputId,direction)

var obj =document.getElementById('dhtmlgoodies_a' + inputId);
var contentObj = document.getElementById('dhtmlgoodies_ac' + inputId);
height = obj.clientHeight;
if(height==0)height = obj.offsetHeight;
height = height + direction;
rerunFunction = true;
height = contentObj.offsetHeight;
rerunFunction = false;
height = 1;
rerunFunction = false;

obj.style.height = height + 'px';
var topPos = height - contentObj.offsetHeight;
contentObj.style.top = topPos + 'px';
setTimeout('slideContent(' + inputId + ',' + direction + ')',dhtmlgoodies_timer);
if(objectIdToSlideDown && objectIdToSlideDown!=inputId){
document.getElementById('dhtmlgoodies_a' + objectIdToSlideDown).style.display='block';
document.getElementById('dhtmlgoodies_a' + objectIdToSlideDown).style.visibility='visible';
dhtmlgoodies_slideInProgress = false;
dhtmlgoodies_activeId = inputId;
dhtmlgoodies_slideInProgress = false;
function initShowHideDivs()
var divs = document.getElementsByTagName('DIV');
var divCounter = 1;
for(var no=0;no<divs.length;no++){
divs[no].onclick = showHideContent;
divs[no].id = 'dhtmlgoodies_q'+divCounter;
var answer = divs[no].nextSibling;
while(answer && answer.tagName!='DIV'){
answer = answer.nextSibling;
answer.id = 'dhtmlgoodies_a'+divCounter;
contentDiv = answer.getElementsByTagName('DIV')[0];
contentDiv.style.top = 0 - contentDiv.offsetHeight + 'px';
contentDiv.id = 'dhtmlgoodies_ac' + divCounter;
window.onload = initShowHideDivs;

If anybody could help me solve this issue that would be great.

Cheers Danny

09-25-2008, 10:45 PM
save the entire thing in a .js file, and then call it in the <head> section of your doc with something like:

<script src="myjavascript.js" type="text/javascript"></script>

09-26-2008, 10:34 AM
I have already tried that.

When I do this the expanding bit stops working. So I imagine there must be something in the code I need to change in order for it to work externally.

I no very little javascript but something in the code must be set for when the page loads the script works. Like an onload function or something.

I have no clue.

I just wanted to trim my page of as much code clutter as possible. If anybody can help me get rid of this chunk of code to external page and it still work then that would be great.

09-26-2008, 11:34 AM
Ensure that on your external JS, you don't have this line of code:


If nothing works, please provide a link to the page in question.

09-26-2008, 05:50 PM
My apologies

I had left the script tags in the js file.

Thanks for your help guys it is working fine now.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum