function readURL(input, imgTag) { if (input.files && input.files[0]) { var reader = new FileReader(); reader.onload = function (e) { $(imgTag).attr('src', e.target.result).show(); } reader.readAsDataURL(input.files[0]); } } $("#profile-img").change(function(){ readURL(this, "#profile-img-tag"); }); $("#profile-img2").change(function(){ readURL(this, "#profile-img-tag2"); });