Translate simple php to javascript

J

Jason2k1

Guest
I have a picture gallery on one of my sites which displays thumbnails of all the pictures and when a picture is clicked it pops up a window with the enlarged picture in it. i currently use php to do this, but i would like to translate it into a client-side language like javascript.

the url of the page that displays the pictures is:
pictureviewer.php?src=name.jpg where name is the name of the picture.

the current code i use is this:

PHP:
<HTML>

<HEAD>

<TITLE>Picture Viewer</TITLE>

</HEAD>

<BODY bgcolor="#99cc00" topmargin="0" leftmargin="0" rightmargin="0" bottommargin="10">

<TABLE width="100%" height="100%" border="0">

<TR><TD align="center" valign="middle">

<IMG src="images/gallery/<?php echo("$src");?>">

</TD></TR>

</TABLE>

</BODY>

</HTML>

Does anyone know how to get this to work using javascript.

Please help,

Thanks in advance

Jason
 
Try this. It only works with one parameter though!

PHP:
<HTML>
<HEAD>
<TITLE>Picture Viewer</TITLE>
</HEAD>
<BODY bgcolor="#99cc00" topmargin="0" leftmargin="0" rightmargin="0" bottommargin="10">
<TABLE width="100%" height="100%" border="0">
<TR><TD align="center" valign="middle">
<SCRIPT>
image = location.href.substring(location.href.lastIndexOf("=")+1,location.href.length);
document.writeln("<IMG src=\\"images/gallery/\\"" +  image+ ">");
</SCRIPT>
</TD></TR>
</TABLE>
</BODY>
</HTML>
 
hey... if neither of you would mind, I would like to know how I might place a picture viewer on my site. I want one that would search a directory and use anything from it (JPG). I tried the code above but was unable to get it to work for me. I greatly appreciate it.
 
Then you need to stick with PHP or something other server-side. You can't use Javascript anyway, no file access.

There are some free u can download (and if you wish, modify) if you look for them. www.sourceforge.net is one place to look.
 
Thanks Zedric, the script didn't work that you gave me, just a few things that i had to change and it worked. Thanks neway, i wunt of got out like that on my own seen as im only a beginner in the javascript language. Ive posted the corrected script below if anyone wants to use it:

PHP:
<HTML>
<HEAD>
<TITLE>Picture Viewer</TITLE>
</HEAD>
<BODY bgcolor="#99cc00" topmargin="0" leftmargin="0" rightmargin="0" bottommargin="10">
<TABLE width="100%" height="100%" border="0">
<TR><TD align="center" valign="middle">
<SCRIPT>
image = location.href.substring(location.href.lastIndexOf("=")+1,location.href.length);
document.writeln("<IMG src=\"images/gallery/"+image+"\">");
</SCRIPT>
</TD></TR>
</TABLE>
</BODY>
</HTML>
 
*doh!*
You're right, that " did come on the wrong side of "image". That's what you get for not testing the code. :)
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,621
Latest member
naeemsafi
Back