If user is selecting file and after it if user is unchecking checkbox than file is also at there so I want to make it like a when user is unchecking checkbox than after file is must be remove. How can I make it? And which event handler is perfect for checkbox? HTML CODE:
<div class="checkbox">
<label for="email">electronics
<input type="checkbox" name="product_category[]" value="electronics" id="product_category" class="electronics">
</label>
</div>
<div class="form-group" id="efileu" style="display:none;" >
<input type="file" name="checkboxfile0" id="efile" style="width:100%">
</div>
<div class="checkbox">
<label for="email">kitchen
<input type="checkbox" name="product_category[]" value="kitchen" id="product_category" class="kitchen">
</div>
<div class="form-group" id="kfileu" style="display:none;" >
<input type="file" name="checkboxfile1" id="kfile" style="width:100%">
</div>
<script>
$(".electronics").click(function(){
if(!$("#efileu").is(":visible")){
$("#efileu").show();
}
else{
$("#efileu").hide();
$("#efileu").val();
}
});
$(".kitchen").click(function(){
if(!$("#kfileu").is(":visible")){
$("#kfileu").show();
}
else{
$("#kfileu").hide();
}
});
</script>
</label>
for kitcheninput.file
object, you should clear it's value with$("#efileu input").val("");
. See jsfiddle.net/shaoran/rathxw43.val("")
is not enough, see stackoverflow.com/questions/1043957/…