preview and upload image in jquery
<td>Company Logo:<%= file_field_tag :avatar,name:
"avatar",:onchange => "showimagepreview(this)",:class=>"img_file"
%></td>
<img id="imgprvw" style="width: 167px; height: 94px; margin-top: 8px;" />
<script>
function showimagepreview(input) {
if (input.files && input.files[0]) {
var filerdr = new FileReader();
filerdr.onload = function(e) {
$('#imgprvw').attr('src', e.target.result);
}
filerdr.readAsDataURL(input.files[0]);
}
$('.image_upload').submit();
}
</script>
<img id="imgprvw" style="width: 167px; height: 94px; margin-top: 8px;" />
<script>
function showimagepreview(input) {
if (input.files && input.files[0]) {
var filerdr = new FileReader();
filerdr.onload = function(e) {
$('#imgprvw').attr('src', e.target.result);
}
filerdr.readAsDataURL(input.files[0]);
}
$('.image_upload').submit();
}
</script>
Comments
Post a Comment