JS in PHP
I'm trying to use a JS that creates a scrolling marquee, and the way it works is the text is embedded in the JS file.
My client wants this to be updated by her via online form, so I'm having issues.
At first I tried adding php inside the text of the JS where the text of the marquee is stored, but that didn't work.
Then I tried storing the script as a variable of PHP, with the text of the marquee as $scroll, which was a PHP set variable; but that didn't work.
And then I tried storing the script in a dB, pulling it out, and inserting $scroll's value into the marquee...but that didn't work.
Anybody know how to do this? Thanks alot.
Abhishek Reddy posted this at 04:07 — 19th July 2004.
He has: 3,348 posts
Joined: Jul 2001
Let's see some code.
The first method sounds promising.
Renegade posted this at 10:11 — 19th July 2004.
He has: 3,022 posts
Joined: Oct 2002
One way I can think of is to store the string in an external file then calling it out and setting it as a PHP variable first then as a JS variable.
kb posted this at 13:42 — 19th July 2004.
He has: 1,380 posts
Joined: Feb 2002
The JS with the PHP variable in it:
//Specify the marquee's width (in pixels)
var marqueewidth="300px"
//Specify the marquee's height
var marqueeheight="25px"
//Specify the marquee's marquee speed (larger is faster 1-10)
var marqueespeed=2
//configure background color:
var marqueebgcolor="#DEFDD9"
//Pause marquee onMousever (0=no. 1=yes)?
var pauseit=1
//Specify the marquee's content (don't delete <nobr> tag)
//Keep all content on ONE line, and backslash any single quotations (ie: that\'s great):
var marqueecontent='<nobr><?=$scroll?></nobr>'
////NO NEED TO EDIT BELOW THIS LINE////////////
marqueespeed=(document.all)? marqueespeed : Math.max(1, marqueespeed-1) //slow speed down by 1 for NS
var copyspeed=marqueespeed
var pausespeed=(pauseit==0)? copyspeed: 0
var iedom=document.all||document.getElementById
if (iedom)
document.write('<span id="temp" style="visibility:hidden;position:absolute;top:-100px;left:-9000px">'+marqueecontent+'</span>')
var actualwidth=''
var cross_marquee, ns_marquee
function populate(){
if (iedom){
cross_marquee=document.getElementById? document.getElementById("iemarquee") : document.all.iemarquee
cross_marquee.style.left=parseInt(marqueewidth)+8+"px"
cross_marquee.innerHTML=marqueecontent
actualwidth=document.all? temp.offsetWidth : document.getElementById("temp").offsetWidth
}
else if (document.layers){
ns_marquee=document.ns_marquee.document.ns_marquee2
ns_marquee.left=parseInt(marqueewidth)+8
ns_marquee.document.write(marqueecontent)
ns_marquee.document.close()
actualwidth=ns_marquee.document.width
}
lefttime=setInterval("scrollmarquee()",20)
}
window.onload=populate
function scrollmarquee(){
if (iedom){
if (parseInt(cross_marquee.style.left)>(actualwidth*(-1)+8))
cross_marquee.style.left=parseInt(cross_marquee.style.left)-copyspeed+"px"
else
cross_marquee.style.left=parseInt(marqueewidth)+8+"px"
}
else if (document.layers){
if (ns_marquee.left>(actualwidth*(-1)+8))
ns_marquee.left-=copyspeed
else
ns_marquee.left=parseInt(marqueewidth)+8
}
}
if (iedom||document.layers){
with (document){
document.write('<table border="0" cellspacing="0" cellpadding="0"><td>')
if (iedom){
write('<div style="position:relative;width:'+marqueewidth+';height:'+marqueeheight+';overflow:hidden">')
write('<div style="position:absolute;width:'+marqueewidth+';height:'+marqueeheight+';background-color:'+marqueebgcolor+'" onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=marqueespeed">')
write('<div id="iemarquee" style="position:absolute;left:0px;top:0px"></div>')
write('</div></div>')
}
else if (document.layers){
write('<ilayer width='+marqueewidth+' height='+marqueeheight+' name="ns_marquee" bgColor='+marqueebgcolor+'>')
write('<layer name="ns_marquee2" left=0 top=0 onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=marqueespeed"></layer>')
write('</ilayer>')
}
document.write('</td></table>')
}
}
And the text coming from a db:
<?php
$scroll = stripslashes($qry2['scroll']);
?>
I call later in the page $script which is equal to the JS with $scroll in it
Veter posted this at 06:07 — 20th July 2004.
He has: 18 posts
Joined: Jul 2004
Use echo:
kb posted this at 12:28 — 20th July 2004.
He has: 1,380 posts
Joined: Feb 2002
just so you know....
<?php
=$scroll
?>
Veter posted this at 19:06 — 20th July 2004.
He has: 18 posts
Joined: Jul 2004
Thats right Abhishek Reddy.
Who told you that i dont know that?
Abhishek Reddy posted this at 18:57 — 20th July 2004.
He has: 3,348 posts
Joined: Jul 2001
Indeed, but
<?php
echo $scroll;
?>
kb posted this at 19:55 — 20th July 2004.
He has: 1,380 posts
Joined: Feb 2002
lol...you just made it sound like i was doing it wrong...sorry
Either way, it doesnt' make a difference...and I know for a fact that my server accepts the "short_open_tag" cuz I use it all the time.
Anyways...any ideas here?
jjinno posted this at 16:32 — 21st July 2004.
They have: 18 posts
Joined: Jul 2004
I once (given I dont know your exact situation) had a similar problem, resizing images on the fly, allowing a user to click and expand a photo (the JS) and click and minimize the photo, all on a phpBB.
What we ended up doing (not that this is the best way, or the easiest) was getting rid of the JS file, and writing the entire JS code into the PHP as if it were HTML. The embedded JS was then set with a series of PHP if statements so that only the posted images were resizeable (but this fell in with the MOD for phpBB, so was relatively easy)
Given my very limited knowledge of JS, I was able to google enough info as to how to do this, but also, my JS was not more than maybe 20 lines.
Sorry if Im whack and this is absolutely not what you needed to hear or something. LOL
-----------------------
"I hear and I forget. I see and I remember. I do and I understand." - Confucius
- Jinno
-----------------------
"I hear and I forget. I see and I remember. I do and I understand." - Confucius
Abhishek Reddy posted this at 20:49 — 21st July 2004.
He has: 3,348 posts
Joined: Jul 2001
What's your final output? Is the PHP being parsed? Is the JS in its own file or in the PHP file?
jjinno posted this at 22:00 — 21st July 2004.
They have: 18 posts
Joined: Jul 2004
The JS would be contained within the PHP, which would be parsed.
As for the final output, Im not sure as I know what youre after, but the BB looked just as usual, except now images were resized to a more reasonable (proportions constrained) 200x200, which when the user scrolled over the small image, the words "Double-click for Full Size" would appear. Subsequently the large image also said "Double-click for Thumbnail".
- Jinno
-----------------------
"I hear and I forget. I see and I remember. I do and I understand." - Confucius
kb posted this at 04:21 — 23rd July 2004.
He has: 1,380 posts
Joined: Feb 2002
I have no final output...it doesnt come up...
PHP ...i dunno
separate file? ive tried both ways
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.