I have a set of images stored in an array and I show them through the array with a "foreach".
PHP Code of how I extract the images and show them:
$imagenes = $cabana->getImagenes();
//Recorremos el foreach del array "$imagenes".
$first = true;
foreach($imagenes as $imagen){
if($first){
echo "<img id='grande' src='imagenes/".$imagen."' width='260' height='260'/> ";
$first = false;
}else{
echo "<img class='peque' src='imagenes/".$imagen."' width='140' height='140'/ onclick='cambiarImagen(this)'> ";
}
}
As we can see, there is a superior image in terms of the size of the rest.
The problem is as follows : How do I do it (from the client side, javascript for example) so that when I click on an image of the smaller ones, I replace it with the larger main image? When the images are in an array, how do I know which image to click on? Because I only have one onClick event for all of them.
The idea would be something similar to this illustration: