w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
multiple onclicks for one function

replace this line:

echo "<img
class='littleshow'"."id='foto".$rows[$id]."'src='".$rows[$foto]."'
onclick='Bigscreen(foto".$rows[$id].")'></img>";

with this:

echo "<img
class='littleshow'"."id='foto".$rows[$id]."'src='".$rows[$foto]."'
onclick='Bigscreen(this)'></img>";

and change Bigscreen function to:

function Bigscreen(img) {
    document.getElementById('bigshowcase').innerHTML ='<img src="' +
img.src + '" />';
}

CSS:

<style type="text/css">
#bigshowcase img{max-width:600px;max-height:600px;}
</style>

hope that helps.

EDIT:

note that jQuery is always nicer:

<script src="http://code.jquery.com/jquery-latest.min.js"
type="text/javascript"></script>
<script type="text/javascript">
$(function(){
    $(document).on('click', 'img.littleshow', function(){
        $('#bigshowcase').html('<img src="' + $(this).attr('src') + '"
/>');
    });
});
</script>

will do the job.





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.