Click here to Skip to main content
15,904,415 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the below code and when the "Browse" click, i want place the same content in the div "projectidAppe" and change the "Browse" to "Delete" button .
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label for="exampleInputEmail1">Project Photos</label>
<div class="form-group file-uploader">
  <div class="input-group col-xs-12">
    <span class="input-group-addon">
      
    </span>
    <input type="text" id="txtProjectTitle" style="height: 35px !important" class="form-control input-lg" disabled placeholder="Upload Image">
    <div id="clearbtn" class="input-group-btn">
      <div class="browse btn btn-primary">
        ^__i class="glyphicon glyphicon-search"> Browse
        <input type="file" accept="image/*" id="idProjectTitle" multiple="multiple" name="fileUploadphoto" class="file">
      </div>
    </div>
  </div>
</div>


What I have tried:

I have done this using the following jquery,
JavaScript
$(document).on("change", "#idProjectTitle", function(e) {
  var datatoappend = ' <div class="form-group file-uploader"><div class="input-group col-xs-12"><span class="input-group-addon"></span><input type="text" id="txtProjectTitle" style="height: 35px !important" class="form-control input-lg" disabled placeholder="Upload Image"><div class="input-group-btn"><div class="browse btn btn-primary">^__i class="glyphicon glyphicon-search"> Browse<input type="file" accept="image/*" id="idProjectTitle" multiple="multiple" name="fileUploadphoto" class="file"></div></div></div></div>';
  $("#txtProjectTitle").attr('placeholder', $(this).val().split('\\').pop());
  var btnDelete = '<div id="idImgDelete" class="browse btn btn-primary">Delete</div>';
  $('#clearbtn').html('');
  $('#clearbtn').append(btnDelete);
  $("#projectidAppe").append(datatoappend);
});


But now, not happening each image name inside the txtProjectTitle 's placeholder respectively. After file upload, how can I show delete button for each one and how to delete one row when click on the delete button? Below is showing screen shot,

ddd — imgbb.com[^]
Posted
Updated 9-Apr-17 23:02pm

1 solution

Check this it will work as you expected.

HTML:

HTML
<div id="projectidAppe">
<label for="exampleInputEmail1">Project Photos</label>
<div class="form-group file-uploader">
  <div class="input-group col-xs-12">
    <span class="input-group-addon">
      
    </span>
    <input type="text" id="txtProjectTitle" style="height: 35px !important" class="form-control input-lg" disabled placeholder="Upload Image">
    <div id="clearbtn-0" class="input-group-btn">
      <div class="browse btn btn-primary">
        ^__i class="glyphicon glyphicon-search"> Browse
        <input type="file" accept="image/*" class="idProjectTitle" multiple="multiple" name="fileUploadphoto" class="file">
      </div>
    </div>
  </div>
</div>
</div>


JS:

JavaScript
var count = 1;
$(document).on("change", ".idProjectTitle", function(e) {
  var datatoappend = ' <div class="form-group file-uploader"><div class="input-group col-xs-12"><span class="input-group-addon"></span><input type="text" id="txtProjectTitle" style="height: 35px !important" class="form-control input-lg" disabled placeholder="Upload Image"><div id="clearbtn-'+count+'" class="input-group-btn"><div class="browse btn btn-primary">^__i class="glyphicon glyphicon-search"> Browse<input type="file" accept="image/*" class="idProjectTitle" multiple="multiple" name="fileUploadphoto" class="file"></div></div></div></div>';
  $("#txtProjectTitle").attr('placeholder', $(this).val().split('\\').pop());
  var btnDelete = '<div id="idImgDelete" class="browse btn btn-primary">Delete</div>';
  $('#clearbtn-'+(count-1)).html('');
  $('#clearbtn-'+(count-1)).append(btnDelete);
  $("#projectidAppe").append(datatoappend);
  count ++;
});
$(document).on("click", "#idImgDelete",function(){
    $(this).parentsUntil(".form-group.file-uploader").remove();
});
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900