PDA

View Full Version : Script not running with php includes


urbanrays
11-04-2010, 10:59 AM
Hi

I am building a site using php includes and the trouble I am having is that if I leave this code


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


in the head tags the java script does not run, if I bring it down to here on my content pages

<?php
$title = "Page Name";
include('header.php');
?>
<script type="text/javascript" src="js/file.js"></script>


it works but the yellow java fault triangle on my browser window is showing, is there any way of getting round this problem. sorry I do not have it on a server for you to see, testing on xampp

Thanks in advance for any replies.

davidj
11-04-2010, 11:21 AM
what is in the JS file. Paste the code

urbanrays
11-04-2010, 11:25 AM
// JavaScript Document
function addScrollers() {
startScroll('myscroller','<p>text here<\/p>');
}
var speed=15;
var dR=false;
var step = 2; function objWidth(obj) {if(obj.offsetWidth) return obj.offsetWidth; if (obj.clip) return obj.clip.width; return 0;} function objHeight(obj) {if(obj.offsetHeight) return obj.offsetHeight; if (obj.clip) return obj.clip.height; return 0;} function scrF(i,sH,eH){var x=parseInt(i.top)+(dR? step: -step); if(dR && x>sH)x=-eH;else if(x<2-eH)x=sH;i.top = x+'px';} function startScroll(sN,txt){var scr=document.getElementById(sN); var sW = objWidth(scr)-6; var sH = objHeight(scr); scr.innerHTML = '<div id="'+sN+'in" style="position:absolute; left:3px; width:'+sW+';">'+txt+'<\/div>'; var sTxt=document.getElementById(sN+'in'); var eH=objHeight(sTxt); sTxt.style.top=(dR? -eH : sH)+'px'; sTxt.style.clip='rect(0,'+sW+'px,'+eH+'px,0)'; setInterval(function() {scrF(sTxt.style,sH,eH);},1000/speed);}
window.onload = addScrollers;

davidj
11-04-2010, 12:41 PM
there is an error in your JS

return obj.clip.width; return 0;

You can only have 1 return per function unless its in a condition

urbanrays
11-04-2010, 01:58 PM
Cheers David Sorted it

Going to use <marquee> Instead:o

Being honest I have scrapped the code and got some different code that works fine now.

Thanks again

But dont run away I have another problem that php include's bring, will create a new thread

Corrosive
11-04-2010, 02:02 PM
Going to use <marquee> Instead:o



Yes, very funny. We'll be sending the heavies round later ;)

urbanrays
11-04-2010, 03:00 PM
Yes, very funny. We'll be sending the heavies round later ;)


Not The Bristol Bruisers..

Hope all is well with you mate.

Corrosive
11-04-2010, 05:22 PM
...and this one ;)

urbanrays
11-04-2010, 05:27 PM
Oh no Toby you have moved my threads to where I keep seeing tumble weed go across my screen.:o

Corrosive
11-04-2010, 05:32 PM
Aye, sorry mate but they live in the PHP section I'm afraid. DavidJ is smart enough to find them... trust me ;)

edbr
11-05-2010, 12:57 AM
actually this looks to be more of a javascript error