Translate simple php to javascript

Discussion in 'Web Design & Coding' started by Jason2k1, Apr 1, 2003.

  1. Jason2k1

    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
     
  2. Zedric

    Zedric NTFS Guru Folding Team

    Messages:
    4,006
    Location:
    Sweden
    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>
     
  3. Un4gIvEn1

    Un4gIvEn1 Moderator

    Messages:
    1,084
    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.
     
  4. Zedric

    Zedric NTFS Guru Folding Team

    Messages:
    4,006
    Location:
    Sweden
    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.
     
  5. Jason2k1

    Jason2k1 Guest

    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>
     
  6. Zedric

    Zedric NTFS Guru Folding Team

    Messages:
    4,006
    Location:
    Sweden
    *doh!*
    You're right, that " did come on the wrong side of "image". That's what you get for not testing the code. :)