Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: PHP Simple gallery Javascript Error

  1. #1
    Join Date
    May 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default PHP Simple gallery Javascript Error

    Hi everyone,

    I have a problem solving a javascript issue that I have with the PHP simple gallery.
    http://www.dynamicdrive.com/dynamici...photoalbum.htm.
    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:

    Code:
    <script type="text/javascript">
    function sendcroper(picpath){
       window.open("http://www.otherdomain.com?partnerid=1016&imagepath=" + escape(picpath),
                    "Croper","height=570,width=600,top=50,left=50,scrollbars=no")
    }
    </script>
    Now the function called "sendcroper" I include it in the IMG href:
    Code:
    <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:

    Code:
    javascript:sendcroper(http://www.mydomain.com/pics/c016.jpg)
    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/dynamici...photoalbum.htm for the original code.

    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),
                    "Croper","height=570,width=600,top=50,left=50,scrollbars=no")
    }
    </script>
    <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])
    }
    galleryarray.sort(sortbydate)
    
    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) : ""
    }
    while(document.getElementById("navlink"+y)!=null){
    document.getElementById("navlink"+y).className=""
    y++
    }
    document.getElementById("navlink"+p).className="current"
    }
    
    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>')
    curimage++
    }}
    
    
    </script>
    
    <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> ')
    document.getElementById("navlink1").className="current"
    </script>

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    This thing doesnt work.
    I'm not surprised. Put quotes around the string.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    May 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey
    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.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <a href="javascript:sendcroper(\''+imagecompletepath+'\')" target="'+href_target+'">
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    May 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey
    Code:
    <a href="javascript:sendcroper(\''+imagecompletepath+'\')" target="'+href_target+'">
    thanks it works!

  6. #6
    Join Date
    Jul 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default a question related to your post

    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?

    Meena

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    The outer quotes are part of the HTML.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Jul 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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.

    Meena

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    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).
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    Jul 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default still doesnt work

    Still it doesn't work. By the way, what is the meaning of surrounding '+stringvar+' by \'?

    Meena

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •