4

I am editing my question after in depth searching about my problem basically my website is a fashion display website it displays shoes cloths and bags etc now its obvious that i will be having lots of pics i was solving my problem with jquery and javascript that when a user clicks a thumbnail on the index page or he goes to the menu and clicks the shoes link javascript opens the larger image in a new tab but now i m switcing to php what i did is below

  1. I made a mysql database having paths to the images like images/zara/thumbnails/shoes for thumbnails and images/zara/shoes for the larger images

  2. when the user clicks on the links for ex(shoes) the link text will be grabbed by jquery like this

       $(document).ready(function() {
        $('ul.sub_menu a').click(function() {
            var txt = $(this).text();  
                $.ajax({
                type: 'POST',
                url: 'thegamer.php',
                data: {'txt'}
                });
        });
    });
    

Further pass it to the php file now here i m facing a problem what i need at the moment is

that how will php make search on the basis of that var txt in the database retrieve the thumbnails of the shoes open a new tab say(shoes.html) and display all the available shoes thuumbnails in divs

sajid
  • 247
  • 7
  • 15

5 Answers5

3

Here's the jquery code that should work:

<script>
$(function () {

  $(document).on('click', 'div.prodcls img', function (e) {
    e.preventDefault();
    window.open($(this).attr('src').replace('/thumbnails', ''), '');
  });

});
</script>

And some css for good measure:

<style>
div.prodcls img:hover {
  cursor: pointer;
}
</style>

Here's a working fiddle: http://jsfiddle.net/DenGp/

Jake Feasel
  • 16,785
  • 5
  • 53
  • 66
  • Note, as I hope is obvious - in this code, I assumed that by "new tab", you meant a new browser tab (which most browsers do by default these days when they see a window.open). If you meant something else, this can be easily modified to do just about anything (pop a lightbox, for example). – Jake Feasel Dec 22 '11 at 06:42
  • my jquery is not working as javascript is working i have attached the library in script but not working whats the prblem – sajid Dec 22 '11 at 07:13
  • Can you provide a link? What exactly is not working? Are you getting a javascript error? – Jake Feasel Dec 22 '11 at 07:16
  • what if i target a div to open the image then what will be the code – sajid Dec 22 '11 at 07:30
  • Look into the lightbox answer that DmitryB provided. – Jake Feasel Dec 22 '11 at 07:33
  • window.open($(this).attr('src').replace('images/zara/thumbnails/1.png', 'images/zara/1.png'), ''); i made it like this but not working – sajid Dec 22 '11 at 07:38
  • the problem is that its opening the thumb nail image in the new window where to keep the path of the large image that is images/zara/1.png to open the large image in the new window – sajid Dec 22 '11 at 07:45
  • I've changed my answer to use /thumbnails (with the s). That should work. – Jake Feasel Dec 22 '11 at 07:53
  • dear u r not getting me my problem is that the larger one image from the folder images/zara/1.png must open in the new window ur code is working correct but is opening the thumbnail image in new window i want that by clicking the thumbnail the code goes to the directory images/zara/1.png and open the image in new window – sajid Dec 22 '11 at 08:06
  • The `.replace('/thumbnails', '')` code is supposed to remove that from the current image source (turning images/zara/thumbnails/1.png into images/zara/1.png). In my posted fiddle, it does exactly that. So again, I don't see the problem. – Jake Feasel Dec 22 '11 at 17:53
2

You can open actual image in new browser tab without jQuery:

For Example:

<div id="prodoneid" class="prodcls">
  <a href='images/zara1.png' target='_blank'>
    <img src="images/thumbnail/zara/1.png" alt="ZARA"/>
  </a>
</div>
Naveed
  • 41,517
  • 32
  • 98
  • 131
  • ur code is opening the thumbnail image in the new window i want the large one which is in images/zara/1.png – sajid Dec 22 '11 at 07:51
  • Please use larger image path in **href** of `` – Naveed Dec 22 '11 at 07:53
  • ok it worked but naveed if i want to point a div in a specific page like a
    in this page fprodone.html
    – sajid Dec 22 '11 at 08:14
  • You can use jQuery's `$.ajax()` function to achieve this ? **For Example:** http://stackoverflow.com/questions/3326614/how-to-load-more-than-one-divs-using-ajax-json-combination-in-zend – Naveed Dec 22 '11 at 08:33
2

Css:

#imagePopup{ float:left; z-index:10; position: absolute;} 

Add some positioning

HTML:

<div id="prodtwoid" class="prodcls">
<img src="images/thumbnail/zara/2.png" alt="ZARA"/>
</div>

<div id="prodthreeid" class="prodcls">
<img src="images/thumbnail/puma/1.png" alt="PUMA"/>
</div>

<div id="prodfourid" class="prodcls">
<img src="images/thumbnail/hermes/1.png" alt="HERMES"/>
</div>
//This is you popup div
<div id='imagePopup' style='display:none'>
</div>

JS:

$('.prodcls').click(function(){
   var src = $(this).attr('src').replace('/thumbnail', '');
    $("#imagePopup").html("<img src='"+src+"'/>")
    $("#imagePopup").toggle();
});

Updated answer:

HTML: (give every image a link):

<a href='showImage.php?img=path/of/image.jpg'><img src='path/of/thumb.jpg'/></a>

showImage.php:

$sImagePath = $_GET['img'];
echo "<div class='imgDiv'>";
echo "<img src='$sImagePath' />";
echo "</div>;
Derk Arts
  • 3,432
  • 2
  • 18
  • 36
  • this one is also ok but for gallery – sajid Dec 22 '11 at 07:27
  • ZARA this is my code but it is still openning the thumbnail – sajid Dec 22 '11 at 08:03
  • can u please explain the .attr('').replace('/thumbnail','') – sajid Dec 22 '11 at 13:04
  • `.attr('').replace('/thumbnail','')` replace the part of the SRC that says '/thumbnail' with '', so it actually removes that part. `.html(src)` sets the HTML of the selected element to that source. Actually that should be `.html("")`. Also see: http://api.jquery.com/html/ and http://www.w3schools.com/jsref/jsref_replace.asp – Derk Arts Dec 22 '11 at 13:21
  • plz check lemonx.biz and click on the brown zara shoes it opens it in a new blank html what i want is to open the image in a div in fprod.html how to target that specific div in that html that when the image is clciked the fprod.html opens and the image is there in a div – sajid Dec 22 '11 at 15:20
  • That will be complex without server side scripting. You would need to get the parameter from the URL and load that in a div. http://snipplr.com/view/799/get-url-variables/ – Derk Arts Dec 22 '11 at 15:38
  • saratis one thing plz tell me how could i be a good programmer sometimes i m so fatup that i decide to quit but... – sajid Dec 22 '11 at 15:57
  • Just keep it up, read tutorials read books, read this website. You will get there in the end. Maybe tomorrow I will have time to help you again. Just comment on me tomorrow to remind me. – Derk Arts Dec 22 '11 at 17:11
  • yes i can use php now i have made a scenarion and working on that which is actually my website is a fashion display website which will have 100s of pics what im doing now is on click event im sending that image info to php which will collect that pic large image from mysql wher i have made a table of images having paths and the display it in a new tab in a div whats ur opinion – sajid Dec 25 '11 at 15:13
  • I don't understand your last comment. But to make it so that you can open the image in a new tab in a DIV, you would need to change some code. Please my answer for the example. – Derk Arts Dec 25 '11 at 15:17
  • i mean that i am switching to php my procedure will be as follow jquery will grab the click event pass via $.ajax the clicked info to php file php will collect the data from my sql and display it on another tab inside a div – sajid Dec 25 '11 at 16:05
0

Perhaps a lightbox is what you really need? take a look at this library: http://www.huddletogether.com/projects/lightbox2/

dbrin
  • 15,525
  • 4
  • 56
  • 83
0

You have an error in your AJAX code (your forgo to include the actual var:

$(document).ready(function() {
    $('ul.sub_menu a').click(function() {
        var txt = $(this).text();  
            $.ajax({
            type: 'POST',
            url: 'thegamer.php',
            data: {'txt':txt}  //added :txt here
            });
    });
});

Now in PHP:

$txt = $_GET['txt'];
//Now lookup $txt in you msyql db
//And echo the result, so JS can read it.
Derk Arts
  • 3,432
  • 2
  • 18
  • 36
  • data: {'txt':txt} //added :txt here with ur this code u r making the link catch static i have a number of items like jeans trousers shoes shirts bags caps and a lot more i want to make it dynamic that whatever link is clicked the the jquery grabs the text and forward it to the php in ur code shall i mention the code like this 'txt':shoes – sajid Dec 26 '11 at 07:56