lundi 23 février 2015

Getting jsfiddle 'show image file' working

I've sure I'm missing something simple here, I found a suggestion on here to use jsfiddle for code to preview an image before upload: http://ift.tt/1GlwJ6O


But I can't get it to work. I'm assuming I just put the javascript in the header wrapped in tags?


Here's my code (thank you - I'm sorry if this is very similar to other questions)





<script language="javascript">
window.onload=function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();

reader.onload = function (e) {
$('#artworkshow').attr('src', e.target.result);
}

reader.readAsDataURL(input.files[0]);
}
}

$("#artwork").change(function(){
readURL(this);
});
</script>



<img id="artworkshow" src="#" alt="Image Preview" />
<p>
<label for="artwork">Artwork</label>
<input id="artwork" name="artwork" type="file" class="inputAuto" />
Size: 700px by 260px</p>
<p>



Aucun commentaire:

Enregistrer un commentaire