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

//
//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

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s