javascript - How to pass the img src into the Bootstrap modal? -



javascript - How to pass the img src into the Bootstrap modal? -

now i'm getting src of images in loop. problem can't pass through modal show right image. matter of fact, can't show image. here's code.

<script src="js/jquery-2.0.3.min.js" type="text/javascript"></script> <?php $sql = "select * portfolio"; $query = mysqli_query ($conn, $sql); ?> <div class="col-md-12"> <h1>portfolio</h1> <table class="table"> <?php while ($row = mysqli_fetch_assoc($query)) { ?> <tr> <td> <br> <a data-toggle="modal" data-target="#mymodal1"> <img src="<?php echo $row ['pic']; ?>" width="200" height="150" class="getsrc"> </a> <br><br> </td> <td> <h4><a href="<?php echo $row ['link']; ?>" target="_blank"><?php echo $row ['projectname']; ?></a></h4> <?php echo $row ['description']; ?><br><br> <strong class="text-warning"><?php echo $row ['note']; ?></strong> </td> </tr> <?php } ?> </table> </div> <script type="text/javascript"> $('.getsrc').click(function() { var src =$(this).attr('src'); $('.showpic').attr('src') = src; }); </script> <!-- modal --> <div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="mylargemodallabel" aria-hidden="true" id="mymodal1"> <div class="modal-dialog modal-lg"> <div class="modal-content"> <div class="col-md-12"> <img src="" class="img-responsive" class="showpic"> </div> </div> </div> </div>

as comment says, ids need unique. should utilize class instead.

<?php while ($row = mysqli_fetch_assoc($query)) { ?> <img src="<?php echo $row['pic']; ?>" width="100" height="100" class="getsrc"> <?php } ?> <script type="text/javascript"> $('.getsrc').click(function() { var src = $(this).attr('src'); alert (src); }); </script>

javascript php jquery image while-loop

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -