Advertisement
Bedhoel

Untitled

Aug 24th, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. var Ids = 1;
  2. function tambah_data(){
  3. var html ='<div id="file_div_'+Ids+'" >';
  4. html+='<div class="row"><div class="col-md-2">';
  5. html+=' <input type="text" placeholder="Nama File" class="form-control" name="nama_file[]">';
  6. html+='</div>';
  7. html+='<div class="col-md-2">';
  8. html+=' <input type="file" name="file[]" onChange="readImage(this,'+Ids+')">';
  9. html+='</div>';
  10. html+='<div class="col-md-2">';
  11. html+=' <button onClick="removeFile(\''+Ids+'\');" type="button" class="btn btn-danger">X</button>';
  12. html+='</div></div>';
  13. html+='<div class="row">';
  14. html+='<div class="col-md-5">';
  15. html+='<br/><img style="width:150px;height:150px" id="img_'+Ids+'">';
  16. html+='</div>';
  17. html+='</div>';
  18. html+='<br/></div>';
  19. $("#gen_data").append(html);
  20. Ids++;
  21. }
  22. function removeFile(Ids){
  23. $('#file_div_'+Ids).remove();
  24. }
  25.  
  26. function readImage(input,ids){
  27. if (input.files && input.files[0])
  28. {
  29. var reader = new FileReader();
  30. reader.onload = function (e) {
  31. $('#img_'+ids).attr('src', e.target.result);
  32. }
  33. reader.readAsDataURL(input.files[0]);
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement