Jump to content

Passing a php var to javascript


dk4210

Recommended Posts

Hello Guys,

 

I have a page with thumb nails and a large image that changes when clicking on thumbnail. I need to display dynamic title for the image. It wont display because the page is not reloading.. How do you pass the name so it will show up without reloading?

 

Here is the JS for switching dynamically loading the large image

 

<script language="javascript">
$(document).ready(function() {
    $('.thumbnail').live("click", function() {
        $('#mainImage').hide();
        $('#atitle').hide();
        $('#imageWrap').css('background-image', "url('/images/ajax-loader.gif')");
        var i = $('<img />').attr('src',this.href).load(function() {
            $('#mainImage').attr('src', i.attr('src'));
             $('#imageWrap').css('background-image', 'none');
            $('#mainImage').fadeIn();
             $('#atitle').fadeIn();
            
           
        });
        return false; 
    });
});
</script>

 

Here is the link for the thumb

 

  // Thumbnail Display
             
             echo '<a href="artists/'.$artist.'/'.$imgname.'.jpg" class="thumbnail"><img src="artists/'.$artist.'/previews/'.$imgname.'.jpg" border="0" /></a>';

 

[/code]

 

Link to the large image

 

  // Large image display              
                            echo '<img src="artists/'.$artist.'/'.$first_image.'.jpg" alt="Main Image" id="mainImage"/>';

 

Here is the php echo for the title

<? echo  str_replace('"', '`',  $iname); ?>

 

I need to some how pass a php var from the thumb link to the js and have it display dynamically (Without Reloading)

 

Hope I explained this correctly.. Please advise..

 

Thanks, Dan

Link to comment
https://forums.phpfreaks.com/topic/258581-passing-a-php-var-to-javascript/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.