How can a PHP script be modified to display a large image next to a thumbnail when clicked?
To display a large image next to a thumbnail when clicked in a PHP script, you can use JavaScript to handle the click event and dynamically change the source of the large image element. You can create a function that updates the src attribute of the large image element with the clicked thumbnail's source. This way, when a thumbnail is clicked, the corresponding large image will be displayed.
<?php
// HTML code for thumbnails and large image
echo '<img src="thumbnail1.jpg" class="thumbnail" onclick="showLargeImage(this.src)">';
echo '<img src="thumbnail2.jpg" class="thumbnail" onclick="showLargeImage(this.src)">';
echo '<img src="thumbnail3.jpg" class="thumbnail" onclick="showLargeImage(this.src)">';
echo '<img src="thumbnail4.jpg" class="thumbnail" onclick="showLargeImage(this.src)">';
echo '<img id="largeImage" src="" style="display: none;">';
// JavaScript function to show large image
echo '<script>';
echo 'function showLargeImage(src) {';
echo ' document.getElementById("largeImage").src = src;';
echo ' document.getElementById("largeImage").style.display = "block";';
echo '}';
echo '</script>';
?>
Keywords
Related Questions
- What steps can be taken to troubleshoot and debug session variable issues like the one described in the forum thread?
- What is the significance of using $_SERVER['SERVER_ADDR'] in PHP to obtain the server's IP address?
- How can PHP be used to manipulate arrays and variables within a table creation process?