Thread: PHP-Javascript

    #1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    On planet earth
    Posts
    91
    Rep Power
    10

    PHP-Javascript


    I am not sure where to put this, but bear with me for this thread

    I am working on the project where I have a main photo that is displayed on top of a thumbnail.

    Every time I click the thumbnail, part of the javascript works, as it fades then come back, but doesn't change the photo

    I will only put partial code of the php and javascript as it is far to long to make any sense, plus I am working with Dreamweaver's spry assets, as you can imagine, it is another long code

    The code
    Code:
    <div id="mainPhoto" style="">  
    <table width="100%" align="center" cellpadding="0" cellspacing="0">
      <caption style="/* width:100%;float:left; margin-left:100px; */">
        Photo Gallery without flash
      </caption>
      
      <tr>
    <td id="main" colspan="3" align="center"><img src="images/hi/<?php 
    echo($dispphoto->data[0]['imghi']); ?>" alt="<?php 
    echo ($dispphoto->data[$counter]['desc']);?>" id="main" /></td>
      </tr>
      <tr>
    <?php 
      
      //for each statement (top half)
      for($counter=0; $counter < $photo_count; $counter++){
    ?>
    
    <td align="center"><a href="javascript:;" onClick="MM_swapImage('main','',
    'images/hi/<?php 
    echo($dispphoto->data[$counter]['imghi']);?>',1)">
    <img style="border: 3px solid #000;"
    src="images/lo/<?php 
    echo($dispphoto->data[$counter]['imglo']);?>" title="<?php 
    echo ($dispphoto->data[$counter]
    ['desc']);?>" width="196" height="131" id="t<?php 
    echo $counter + 1; ?>" onClick="MM_effectAppearFade('main', 1000, 25, 100, false)" 
    onMouseOver="MM_changeProp('${"thumb"}','','borderColor','deepskyblue','IMG')" 
    onMouseOut="MM_changeProp('thumb','','borderColor','black','IMG')" /></a></td>
    <?php 
    //for each statement (finishing brace curly bracket)
    }
    ?>
    
    </tr>
    </table>
    I just tidied up the code for easy reading
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2008
    Posts
    22
    Rep Power
    0
    I'm not sure, but I think you're trying to have this work so that when the user clicks the image, it fades and then shows the next photo in the array $dispphoto->data

    If so, the issue is that once the PHP outputs the page to the browser, it's no longer involved. Javascript takes over at that point.

    So, if I'm understanding the problem, you'll need to have PHP write out some javascript which sets up a javascript data structure containing the information that javascript will need to use to figure out what to shown when the user clicks on thumbnail. Alternatively, the javascript could fetch the image info via AJAX from a PHP script.
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    On planet earth
    Posts
    91
    Rep Power
    10
    How do I break this down so I can echo out the javascript?

    I know there are backslashes to escape from javascript when there is a need for php or vice versa, but am a bit confused
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    On planet earth
    Posts
    91
    Rep Power
    10
    Ah, found out what was causing the problem, it was this
    Code:
    <td id="main" colspan="3" align="center">
    I've changed it to
    Code:
    <td colspan="3" align="center">
    Me thinks the javascript/jquery was getting very confused, hence causing the problem

IMN logo majestic logo threadwatch logo seochat tools logo