0

Guy, I've created a form where I have a field for attaching files. The attachment process is working properly. But, if I open a new form, the previous attachment is also getting displayed and it is getting attached too(even if I don't attach any file). I've also tried clearing it, but it's not working. This is how I've tried:

html:

<div class="row">
                    <div class="col-sm-6">
                        <div class="form-group">
                            <label class="col-sm-6">Attachment</label>
                            <div class="col-sm-6">
                                <input type="file" name="attachment" id="attachment">
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-6">
                        <div class="form-group">
                            <label id="attachment_label" name="attachment_label"></label>
                        </div>
                    </div>
                </div>

jquery:

 function clear_invoice_request_controls(){
           jQuery("#attachment_label").html("");
    }

The above jquery shows, how I clear the control. I've tried using, val(), detach(), but it not getting cleared. When I click a new form, that attachment should not be present, but that is not happening. Even if I don't select any attachment, the attachment is getting saved. I don't know what is the mistake. Can someone help me out? I've also shown my html check that out.

SSS
  • 703
  • 4
  • 11
  • 23

1 Answers1

1

Try clearing file input also..

function clear_invoice_request_controls(){
       jQuery("#attachment_label").html("");
       jQuery("#attachment").val("");
}
Lokesh_Ram
  • 391
  • 4
  • 10
  • you are trying to set label val blank. but it will be used for inputs. – Ranjeet Singh May 18 '16 at 09:46
  • 1
    The relative path of the attachment file will be stored in $('#attachment').val().. So by clearing both input and label will clear things related to attachments in the form.. – Lokesh_Ram May 18 '16 at 09:57