Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. //functions on change event of file input to select different file
  2. $('body').on('change', '#image_data', function(){
  3. if (this.files && this.files[0]) {
  4. abc += 1; //increementing global variable by 1
  5.  
  6. var z = abc - 1;
  7. var x = $(this).parent().find('#previewimg' + z).remove();
  8. $(this).before("<div id='abcd"+ abc +"' class='abcd'><img id='previewimg" + abc + "' src=''/></div>");
  9.  
  10. var reader = new FileReader();
  11. reader.onload = imageIsLoaded;
  12. reader.readAsDataURL(this.files[0]);
  13.  
  14. }));
  15. }
  16. });
  17.  
  18. //To preview image
  19. function imageIsLoaded(e) {
  20. $('#previewimg' + abc).attr('src', e.target.result);
  21. };
  22.  
  23. success: function(data)
  24. {
  25. $("#previewimg" + abc).remove();
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement