TinyPortal

General => Chit chat => Topic started by: Jpg on October 08, 2006, 05:48:22 PM

Title: Javascript in php?
Post by: Jpg on October 08, 2006, 05:48:22 PM
Ok I'm having trouble peoples...
As you guys know something happened to my host so my site went down...
So I started from scratch. I lost all 70 members and all my mods and themes I was working on.
Well I need some help designing a new theme.
All I need to know is how to put a js file[Javascript] in the index.template.php.
Not the variables but to call it in a table perhaps.
Is this possible?
I don't care about being able to edit the Javascript through php..undertsnad?

I just need help with this and that is all.  :uglystupid2:
Title: Re: Javascript in php?
Post by: IchBin on October 08, 2006, 06:03:20 PM
echo '<script src="your/file.js"></script>';
Title: Re: Javascript in php?
Post by: Jpg on October 08, 2006, 06:13:11 PM
Lol..that's it? Thanks.
Let me see if that works... Now what if I wanted to do html...is that possible?

Title: Re: Javascript in php?
Post by: IchBin on October 08, 2006, 06:16:39 PM
Same thing. echo 'all your html codes in here';
Title: Re: Javascript in php?
Post by: Jpg on October 08, 2006, 06:56:31 PM
I seperated the code using the above methods...
Hmmm...the code I have isn't working in the index.template.php...but when I put it in a scriptbox it works perfectly...

Any suggestions?
Title: Re: Javascript in php?
Post by: IchBin on October 08, 2006, 06:58:08 PM
Post your code or something so we can take a look.
Title: Re: Javascript in php?
Post by: Jpg on October 08, 2006, 06:59:24 PM
<script type="text/javascript">

/***********************************************
* AnyLink Drop Down Menu- ÂÃ,© Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

//Contents for menu 1
var menu1=new Array()
menu1[0]='<a href="http://www.javascriptkit.com">JavaScript Kit</a>'
menu1[1]='<a href="http://www.freewarejava.com">Freewarejava.com</a>'
menu1[2]='<a href="http://codingforums.com">Coding Forums</a>'
menu1[3]='<a href="http://www.cssdrive.com">CSS Drive</a>'

//Contents for menu 2, and so on
var menu2=new Array()
menu2[0]='<a href="http://cnn.com">CNN</a>'
menu2[1]='<a href="http://msnbc.com">MSNBC</a>'
menu2[2]='<a href="http://news.bbc.co.uk">BBC News</a>'

var menuwidth='165px' //default menu width
var menubgcolor='lightyellow'  //menu bgcolor
var disappeardelay=250  //menu disappear speed onMouseout (in miliseconds)
var hidemenu_onclick="yes" //hide menu when user clicks within menu?

/////No further editting needed

var ie4=document.all
var ns6=document.getElementById&&!document.all

if (ie4||ns6)
document.write('<div id="dropmenudiv" style="visibility:hidden;width:'+menuwidth+';background-color:'+menubgcolor+'" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>')

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}


function showhide(obj, e, visible, hidden, menuwidth){
if (ie4||ns6)
dropmenuobj.style.left=dropmenuobj.style.top="-500px"
if (menuwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=menuwidth
}
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=0
if (whichedge=="rightedge"){
var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var topedge=ie4 && !window.opera? iecompattest().scrollTop : window.pageYOffset
var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
}
}
return edgeoffset
}

function populatemenu(what){
if (ie4||ns6)
dropmenuobj.innerHTML=what.join("")
}


function dropdownmenu(obj, e, menucontents, menuwidth){
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
clearhidemenu()
dropmenuobj=document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv
populatemenu(menucontents)

if (ie4||ns6){
showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth)
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
}

return clickreturnvalue()
}

function clickreturnvalue(){
if (ie4||ns6) return false
else return true
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function dynamichide(e){
if (ie4&&!dropmenuobj.contains(e.toElement))
delayhidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
delayhidemenu()
}

function hidemenu(e){
if (typeof dropmenuobj!="undefined"){
if (ie4||ns6)
dropmenuobj.style.visibility="hidden"
}
}

function delayhidemenu(){
if (ie4||ns6)
delayhide=setTimeout("hidemenu()",disappeardelay)
}

function clearhidemenu(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}

if (hidemenu_onclick=="yes")
document.onclick=hidemenu

</script>
<a href="default.htm" onclick="return clickreturnvalue()" onmouseover="dropdownmenu(this, event, menu1, '150px')" onmouseout="delayhidemenu()">Web Design</a> |

<a href="default2.htm" onclick="return dropdownmenu(this, event, menu2, '200px')" onmouseout="delayhidemenu()">News Sites</a> (onclick)


Here you go.
Title: Re: Javascript in php?
Post by: Jpg on October 09, 2006, 12:27:13 AM
HELP!!!
Title: Re: Javascript in php?
Post by: akulion on October 09, 2006, 12:37:43 AM
When including it inside the index.template.php file the problem seems to be the ' in the code itself

you see the echo statement opens with a ' like so:

echo '

and ends with another like so

';

So if there are ' in the javascript it will cause the echo statement to end prematurely and so you will get a unexpected end error or something

your best bet is to try and replace all the ' with "
but that may cause the javascript to stop working or may not - still worth a try
Title: Re: Javascript in php?
Post by: stormlrd on October 09, 2006, 12:49:32 AM
backslash before the accents in the java dont change the code just put a backslash before each one except the opening one of the echo and the last one before the semicolon.
Title: Re: Javascript in php?
Post by: Jpg on October 09, 2006, 04:54:21 PM
Man it didn't work..It came up as lke 100 input boxes and I got errors...