Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 139953

show preview of selected images before submitting (php) using only javascript

$
0
0

i am stuck trying to show preview of user selected images ( show multiple images ) in my page , but what i get is that when i select new image it replace the old one

function showImage() {
		var fr=new FileReader();
		var body = document.getElementById('b');
		// when image is loaded, set the src of the image where you want to display it
			fr.onload = function(e) { 
				body.innerHTML+='<img src='+this.result+'>';
			};
		src.addEventListener("change",function() {
			// fill fr with image data
		    fr.readAsDataURL(src.files[0]);
		});
	}
	showImage();
<!DOCTYPE html><html><head><title>img</title><style type="text/css">
		img{
			width: 50%;
			height: 50%;
		}</style></head><body id="b"><input type="file" id="src" style="display: block;"></body></html>

Viewing all articles
Browse latest Browse all 139953

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>