View Full Version : Using JAVASCRIPT in PHP--help!
Velocd
06-04-2002, 01:38 AM
I'm using KuraFire's hack right now on how to remove the register button for members and usercp for guests. Anyway, I've got it working fine but on my forums I use javascript roll-over buttons for these things. I have easily inserted the javascript code into PHP modifying it for PHP, but its not working because it needs the javascript info inlcluded in the headinclude to run. Anyway, can I reference to the template headinclude to receive this info somehow? Or can I just insert all the javascript stuff into the PHP file I'm editing at the top? Any help would be great ;)
scsa20
06-04-2002, 02:46 AM
hmm....I think your best bet is to just put the javascript into the headerinclude template....but if you want to put it in a php file, you need to first end it by adding "?>" then after you put in your js code you need to readd "<?" to contune it...but I still say your best bet is the headerinclude template ;)
Velocd
06-04-2002, 03:01 AM
Hmm...
Well, I've tried putting the javascript code at the top of the PHP file, or inserted inside by closing and opening the PHP tags around it--but that still doesn't work...
And as for the headinclude, it's already in there but will the javascript code in my PHP file (global.php) know to look in the headinclude??
How does this look:
$reg_ucp = "<a href=\"register.php?s=$session[sessionhash]&action=signup\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('register','','https://vborg.vbsupport.ru/images/registerroll.gif',1)\">".
"<img name=\"register\" src=\"https://vborg.vbsupport.ru/images/register.gif\" height=\"16\" ".
"alt=\"Registration is free!\" border=\"0\"></a>";
That is the javascript code I have put into the PHP file.
And here is the script that this code needs to run:
<?php
<script language="JavaScript">
<!--
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.0
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
?>
Inserted just a couple lines above the hack
scsa20
06-04-2002, 03:15 AM
okey, this is what I think you should try....take out the following code from the php file and place it in the phpinclude template:
$reg_ucp = "<a href=\"register.php?s=$session[sessionhash]&action=signup\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('register','','https://vborg.vbsupport.ru/images/registerroll.gif',1)\"><img name=\"register\" src=\"https://vborg.vbsupport.ru/images/register.gif\" height=\"16\" alt=\"Registration is free!\" border=\"0\"></a>";
now add (and remove from any PHP file you might had added it too) to the headerinclude template:
<script language="JavaScript">
<!--
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.0
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
hope that helps
Velocd
06-04-2002, 03:35 AM
Muahahah, I just figured out my silly mistake. I had forgot that the original button still existed in the header file, and was using the id "register" which this new code relied on. And both can't use one id, so I erased the header and its fixed. I make the lamest mistakes sometimes..:p
Thanks for you help anyway!
scsa20
06-04-2002, 03:43 AM
lol, sometimes it's little things that screws up the whole board :D
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.