Below is my jQuery Code:
<script>
$(document).on('click','.quickview', function(){
var **image** = $(this).attr('image');
var testimage = document.getElementById('quickimage');
testimage.src= "<?= base_url().'assets/product_images/'.image.".png"?>";
});
</script>
I want to use this image value to the src attr of img which is in a modal, what is the best way can please help? I will be very thankful to you.
You can't use JavaScript variables in PHP, since PHP runs on the server and finishes before the page is sent to the browser.
But you don't need to use the JS variable in PHP. You can do the concatenation in JavaScript.
testimage.src= <?= json_encode(base_url()) ?> + `assets/product_images/${image}.png`;