I have a modal and I want to choose an image from this modal and when I click “ekle” button I want it to be shown in another div. I’m trying to do this with innerHTML but image src is undefined.
Is there a better way then innerHTML?
If there is no better way how can I fix this undefined problem.
function testFunction() {
var imagesrc = document.getElementsByClassName("selected").src;
document.getElementById("deneme").innerHTML = '<img src="' + imagesrc + '" >';
}
<div class="modal fade" id="hazirresim" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Kategori Hazır Resimleri</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<input type="image" src="images/lol-1.jpg" class="selectable" height="250" width="250" style="padding-right: 3px;padding-bottom: 3px;">
<input type="image" src="images/lol-1.jpg" class="selectable" height="250" width="250" style="padding-right: 3px;padding-bottom: 3px;">
<input type="image" src="images/lol-1.jpg" class="selectable" height="250" width="250" style="padding-right: 3px;padding-bottom: 3px;">
<input type="image" src="images/lol-1.jpg" class="selectable" height="250" width="250" style="padding-right: 3px;padding-bottom: 3px;">
<input type="image" src="images/lol-1.jpg" class="selectable" height="250" width="250" style="padding-right: 3px;padding-bottom: 3px;">
<input type="image" src="images/lol-1.jpg" class="selectable" height="250" width="250" style="padding-right: 3px;padding-bottom: 3px;">
</div>
<div class="modal-footer">
<button onclick="testFunction();" type="button" class="btn btn-info btn-lg btn-block">EKLE</button>
</div>
</div>
</div>
</div>