2

i need to implement image upload whereby a thumbnail appears alongside the buttons.. i have implemented it using function "getAsDataURL",... its not working in in chrome and safari.... any solution??

<script type="text/javascript"> 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'; } </script> <div class="uploading_block_inner"> <div class="uploaded_img_inner"><img id="prevImage" style="display:none;" width="91" height="91" /></div> <div class="submit_button_upload"> <div class="upload"><input type="file" id="" name="myImage" onchange="setImage(this);" /></div> </div> <div class="upload_submit_inner"><input type="submit" name="" value="" /></div> </div> 
2

1 Answer 1

0

Assuming you are using jQuery, I have following solution for you.

$(document).ready(function(){ $('input[type=file]').on('change', setImage); }); 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'; } } 
Sign up to request clarification or add additional context in comments.

1 Comment

I added jQuery document ready event handling which was not there in original code

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.