Input image browse preview before submit through JavaScript

Posted: May 27, 2011 in Browse ME!, JavaScript, PHP Tricks, XHTML
Tags: , , , , ,

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

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

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


//body section


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s