Question:
How to wrap an input file in a form using javascript?

Use the below code to wrap an input file in a form using Javascript:


function resetInputFile(elem) {

  const form = document.createElement('form');

  const parent = elem.parentNode;


  parent.insertBefore(form, elem);

  form.appendChild(elem);

  form.reset();

  parent.insertBefore(elem, form);

  parent.removeChild(form);

}


function resetFileInput() {

  resetInputFile(document.querySelector('#image'));

}


<input type="file" id="image">

<button onclick="resetFileInput()">Reset File Input</button>


Suggested blogs:

>How to keep all query parameters intact when changing page in Django?

>Sending Audio file from Django to Vue

>Creating a form in Django to upload a picture from website

>Fix webapp stops working issue in Django- Python webapp

>Sorting the restframework in Django

>Ways to access instances of models in view in order to save both forms at once in Django

>How to change the layout depending on values in the store?

>How can I show 3 items per row in Vuejs?

>What makes index.html have such kind of name in Django?

>Fix Module Not Found Error in Django


Ritu Singh

Ritu Singh

Submit
0 Answers