I want to do is put a default image file in the img tag if it is empty
or the user havent uploaded his picture yet.
current output: http://jsfiddle.net/LvsYc/3117/
html:
<form id="form1" runat="server">
<img id="Picture" data-src="#" alt="your image" /> <br />
<input type='file' id="imgInp" />
</form>
script:
$(function () {
var loader = 'http://i38.photobucket.com/albums/e149/eloginko/profile_male_large_zpseedb2954.jpg';
$('img[data-src]:not([src])').each(function () {
console.log(this);
var $img = $(this).attr('src', loader),
src = $img.data('src'),
$clone = $img.clone().attr('src', src);
$clone.on('load', function () {
$img.attr('src', src);
});
});
});
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#Picture').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#imgInp").change(function(){
readURL(this);
});