Skip to content

Instantly share code, notes, and snippets.

@mahedi2014
Created June 12, 2015 06:13
Show Gist options
  • Save mahedi2014/f654393798ed7f56cc22 to your computer and use it in GitHub Desktop.
Save mahedi2014/f654393798ed7f56cc22 to your computer and use it in GitHub Desktop.
Make image preview on select and change value of input file value by image name
<img id="previewHolderCustomerSignature" onclick="setImage( this.id, 'fileCustomerSignaturePhoto' );" src="https://placeholdit.imgix.net/~text?txtsize=22&txt=Upload customer signature (225px X 150px)&w=225&h=80&txttrack=0" class="img-thumbnail text-center" style="cursor: pointer">
<input type="file" name="fileCustomerSignaturePhoto" value="" id="fileCustomerSignaturePhoto" class="required borrowerImageFile" style="display: none" >
<script>
function setImage(imageLinkId, inputFileName){
$("#"+inputFileName).trigger('click').change(function() {
if (this.files && this.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
$('#'+imageLinkId).attr('src', e.target.result);
}
reader.readAsDataURL(this.files[0]);
}
});
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment