View Full Version : PHP Simple gallery Javascript Error

05-28-2006, 11:16 PM
Hi everyone,

I have a problem solving a javascript issue that I have with the PHP simple gallery.
I modified it a little bit and I almost have what I want.

I need to be able to open the IMG href to a specific script on other site.
Now I tested it and without the gallery script it works.

I added:

<script type="text/javascript">
function sendcroper(picpath){
window.open("http://www.otherdomain.com?partnerid=1016&imagepath=" + escape(picpath),

Now the function called "sendcroper" I include it in the IMG href:

<a href="javascript:sendcroper('+imagecompletepath+')" target="'+href_target+'">

'+imagecompletepath+' is the image full path.

This thing doesnt work. it opens a windows with an adddress of:


Now I see that there is target="'+href_target+'" in the href with a var href_target="new" a little up.
When I try to remove target="'+href_target+'" from the href, the link does not open a thing and I'm getting Error:Expected ']' on script error windows.
Can anyone point out what is the problem and why removing the "target" from the href makes this problem?

Here is the full scipt code (after removing "target"). You can also visit http://www.dynamicdrive.com/dynamicindex4/php-photoalbum.htm for the original code.

<script src="http://www.mydomain.com/getpics.php" type="text/javascript"></script>
<script type="text/javascript">
function sendcroper(picpath){
window.open("http://www.otherdomain.com/index.aspx?partnerid=1016&imagepath=" + escape(picpath),
<script type="text/javascript">
var dimension="3x3"
var imagepath="http://www.mydomain.com/pics/"

var descriptionprefix=[0]
var gsortorder="desc"
var targetlinkdir=""

function sortbydate(a, b){
return new Date(b[1])-new Date(a[1])

var totalslots=dimension.split("x")[0]*dimension.split("x")[1]

function buildimage(i){
var imagecompletepath=(targetlinkdir!="")? targetlinkdir+galleryarray[i][0] : imagepath+galleryarray[i][0]
var tempcontainer='<a href="javascript:sendcroper('+imagecompletepath+')">'
tempcontainer+='<img border="0" src="'+imagepath+galleryarray[i][0]+'" title="" />'
tempcontainer+='</a><br />'
return tempcontainer

function jumptopage(p){
var startpoint=(p-1)*totalslots
var y=1;
for (i=0; i<totalslots; i++){
document.getElementById("slide"+i).innerHTML=(typeof galleryarray[startpoint+i]!="undefined")? buildimage(startpoint+i) : ""

var curimage=0
for (y=0; y<dimension.split("x")[1]; y++){
for (x=0; x<dimension.split("x")[0]; x++){
if (curimage<galleryarray.length)
document.write('<div id="slide'+curimage+'" class="slideshow">'+buildimage(curimage)+'</div>')


<div align="center" id="navlinks">
<script type="text/javascript">
for (i=1; i<Math.ceil(galleryarray.length/totalslots)+1; i++)
document.write('<a id="navlink'+i+'" href="javascript:jumptopage('+i+')\">&nbsp;&nbsp;'+i+'&nbsp;&nbsp;</a> ')

05-28-2006, 11:28 PM
This thing doesnt work. I'm not surprised. Put quotes around the string.

05-29-2006, 08:37 AM
I'm not surprised. Put quotes around the string.

Put quotes where?

I'm removing the target tag in the IMG href, and after that I recieve the error.

05-29-2006, 10:11 AM
<a href="javascript:sendcroper(\''+imagecompletepath+'\')" target="'+href_target+'">

05-29-2006, 05:35 PM
<a href="javascript:sendcroper(\''+imagecompletepath+'\')" target="'+href_target+'">

thanks it works! :)

07-05-2007, 02:32 AM
WHat are we trrying to do by putting in quotes as "'+href_target+'"

I want to understand when we can use '+stringvariable+' and when we need the outer quotes?

What exactly '+stringvariable+' would mean?


07-05-2007, 08:21 AM
The outer quotes are part of the HTML.

07-06-2007, 03:45 AM
The folowing onclick handler code works:

text += '<p><button name="MapIt" type="submit" onClick=(function(x,y){ alert(x);alert(y);})('+i+','+data.events.event[i].latitude+')>MAPIT</button>'+'</p>';

But when I replace the float ( latitude) by a string (venue_address) it doesnt work. Look below:

When I surrounded with outer quotes also, venue_address did not work. Do you know how it should be for that to work?

text += '<p><button name="MapIt" type="submit" onClick=(function(x,y){ alert(x);alert(y);})('+i+','+data.events.event[i].venue_address+')>MAPIT</button>'+'</p>'; did not work.

Also (function(x,y) { alert(x); alert(y); }) ('+i+',data.events.event[i].venue_address) did not work.


07-06-2007, 09:12 AM
text += '<p><button name="MapIt" type="submit" onclick="(function(x,y){ alert(x);alert(y);})('+i+',\''+data.events.event[i].venue_address+'\');">MAPIT</button></p>';You shouldn't be using <button> for submission, though... if I recall correctly, it has problems in IE. You should also use the submit event of the form rather than the click event of the button, since there are other ways of submitting a form (such as pressing enter on a textbox).

07-06-2007, 02:52 PM
Still it doesn't work. By the way, what is the meaning of surrounding '+stringvar+' by \'?


07-06-2007, 03:45 PM
Thank you very much. It works now with your suggestion by surrounding /'.
I had a unwanted third parameter. I removed the third parameter. It then worked.

07-06-2007, 04:08 PM
By the way, what is the meaning of surrounding '+stringvar+' by \'?All string literals in Javascript must be surrounded by quotes.