views:

277

answers:

1

here is my code below. i have a lists of thumbnail images. when the user click a small thumbnail image, it swaps it to show the full image. i have been trying to get the anchor tag name so that, i can explode the value "i". but i get no luck, any ideas?

many thanks!

my javascript

     function swap(image) {
         document.getElementById("main").src = image.href;
     }

my html & php script

                            <img id="main" src="images/main.jpg" width="226" height="226" alt="" />

                                <p><strong>Day <?php echo $i; ?>:</strong></strong><br /><?php echo $today[$i]; ?></p>
                            </div>
                        </div>

                        <?php
                        for($i=1; $i<$day; $i++)
                        {
                            echo'<a href="images/prevDay-'.$i.'.jpg" name="day-'.$i.'" onclick="swap(this); return false;">';
                            echo'<img src="images/thumbDay-'.$i.'.jpg" width="50" height="50" alt="" title="thumbDay-'.$i.'.jpg" /></a> ';

                        }
                        ?>
A: 

You'd be better giving it an ID instead or as well.

Accessing in jQuery then would be (for example):

$("#day-1")

Or without jQuery, just using your document.getElementById.

If you really want to get it by name:

$("a[name='day-1']")
James Wiseman
i think i might have to declare another event so that the first event swap the image, and the second event will get me the anchor tag name. i did included another event like this. (a href="images/prevFeb-1.jpg?prevDay=1" onclick="swap(this); getAnchorName(); return false;") unfortunately, when i click to swap my image, it went to a different page, rather than the swap window. any ideas?
Menew