i have this following script :
$(function() {
var no_of_file = {{$image_counter}};
$('#remove-file').click(function() {
no_of_file--;
});
if (no_of_file >= '5'){
$("#dv1").hide();
$("#imageLabel").hide();
}else{
/* Append More Input Files */
$('#anc_add_more').click(function() {
no_of_file++;
// alert(no_of_file);
if(no_of_file < {{$role_pic_limit}})
{
$('#spn_inputs').append('<span><input type="file" name="myfile[] id="fileChooser" style="float:right;"/><a href="javascript:void(0);" onclick="$(this).parent().remove();" style="float:left;" id="remove-file" >Remove</a><br/></span>');
}
else{
alert("You can upload only {{$role_pic_limit}} images");
}
});
}
});
When i click "Add more file" i append more input and add +1 to no_of_file,my problem is when i try press Remove , it's should down -1 to no_of_file var , why it's not down increment ?
EDIT 15/02:
$(function() {
var no_of_file = {{$image_counter}};
if (no_of_file >= '5'){
$("#dv1").hide();
$("#imageLabel").hide();
}else{
/* Append More Input Files */
$('#anc_add_more').click(function() {
no_of_file++;
// alert(no_of_file);
if(no_of_file < {{$role_pic_limit}})
{
$('#spn_inputs').append('<span><input type="file" name="myfile[]" class="fileChooser" style="float:right;"/><a href="javascript:void(0);" onclick="$(this).parent().remove();" style="float:left;" id="remove-file" >Remove</a><br/></span>');
}
else{
alert("You can upload only {{$role_pic_limit}} images");
}
});
$(document).on('click', '#remove-file,.anc_delete_more', function() {
no_of_file--;
});
}
});
This is now working , but decrease is not perfect is like that :
Click add more file +1
Click add more file +1
Click add more file +1
Click remove more file -1
Click remove more file nothing no decrease
Click remove more file nothing no decrease
jsfiddle:
https://jsfiddle.net/dgh3ndpm/2/
please view jsfiddle i have uploaded what i am using , and you can see clearly the issue , press add more 5 times , then press remove and then press add more again. thanks a lot
You can see how it's work not that good why ?