Archive for the ‘JavaScript’ Category

Hello everyone.

some time we need to show image preview  as user, admin browse any image to post to db or to move to server directory here is the code. i hope it will be helpful for you

//
//css
#prevImage {
border: 8px solid #ccc;
width: 300px;
height: 200px;
}

function setImage(file) {
if(document.all)
document.getElementById('prevImage').src = file.value;
else
document.getElementById('prevImage').src = file.files.item(0).getAsDataURL();
if(document.getElementById('prevImage').src.length > 0)
document.getElementById('prevImage').style.display = 'block';
}

//

//body section

Advertisements