Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,383
    Thanks
    264
    Thanked 32 Times in 31 Posts

    can i mix php and javascript on a onclick

    Hi can i mix php and javascript on an onclick function call like this


    PHP Code:

    <script type="text/javascript">

     function show_big()
      {  

        <?php 
        $k
    =0;
         foreach(
    $fullpic_array as $key => $imagelink
          {
           
    /* remove the single quotes from each value now that you have the comma seperation */
           
    $fullpic_array[$k] =  str_replace("'","",$fullpic_array[$k]);
           
    $medpic_array[$k] = str_replace("'","",$medpic_array[$k]);


          
    $imagenow "<a href='".$fullpic_array[$k]."' rel='lightbox[myprofile]'><img src='".$CONST_LINK_ROOT.'/'.$medpic_array[$k]."' border='0' alt='' /></a>";
          
         echo 
    $imagenow;
     
           
    $k++;
           }
    //close foreach 
           
    ?> 

    }//close function show_big 

    </script>
    and then i call it like this


    PHP Code:

    Total pics = <a href="#" onclick="show_big();"><?=$no_of_pics;?></a>
    its not working which is why im asking lol
    Last edited by durangod; 10-30-2012 at 08:09 PM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Yep. PHP is preprocessed though, so you'll end up with whatever is in $imagenow on the last iteration. You can't interact with it in any way of course since PHP is not capable of responding to client events.
    So yep, you can create JS code with PHP. Nope you cannot interact with PHP using JS.

  • #3
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,383
    Thanks
    264
    Thanked 32 Times in 31 Posts
    Thanks Fou-Lu, i changed the foreach to a while

    PHP Code:

    while($k count($fullpic_array))
     { 
    But i will have to look at this in the morning again, im getting very tired, its still not even trying to open the images in the lightbox and i did test the $imagenow seperately and it is correct it does work if i take it out of the function and just manually assign it to [0] rather than $k,

    but ill look at it again tomorrow, i may end up having to open a window and display them on a sep window first.

    Thanks so much... im headed to bed

  • #4
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,383
    Thanks
    264
    Thanked 32 Times in 31 Posts
    @Fou-Lu

    i got it, that was the last item on the list for this deal and thanks for all your help.

    The fix was so obvious and right there in front of me but i was so tired and stressed over this that i just didnt see it. Remember that i said i may have to open another window for the lightbox. In the back of my mind i kept thinking there has to be a way im not the first one to have this issue.

    I just kept thinking two things, they must be on a page first, and you have to click them, before it will work. And then it hit me like a ton of bricks man, i about fell out of my chair, and i remember i had seen it before on other sites but just didnt pay attention.

    I just listed the images 30x30 in a row under the main image side by side, they are large enough to make out the image somewhat and small enough to put 8 of them under there before making another row.

    Now i have them listed on the page using that array we made and now i can use lightbox, you click on one and then you can click next and prev images. I honestly have seen this setup so many times but it just never hit me till now after much needed sleep and after stressing all weekend over this.

    Also doing it this way i did not have to use it wrapped in a function so much better.

    Thanks sooooooooooooooo much for your help, really appreciate it..
    Last edited by durangod; 10-30-2012 at 05:54 PM.


  •  

    Posting Permissions

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