I create a download control in javascript and then using element.click() to open the file browser dialog.
function add(type) { var element = document.createElement("input"); element.setAttribute("type", type); element.setAttribute("value", type); element.setAttribute("name", type); element.setAttribute("id", "element-" + i); var removebutton = document.createElement('a'); var removeimage = document.createElement('img'); removeimage.setAttribute("width", 15); removeimage.setAttribute("height", 15); removeimage.setAttribute("class", "removebutton"); removeimage.src = "/Content/Images/redx.png"; removebutton.appendChild(removeimage); removebutton.setAttribute("id", "remove-" + i); removebutton.setAttribute("onclick", "remove(" + i + "); return 0;"); var newfile = document.getElementById("uploadhere");
The File Browser dialog box is suitable for its purpose, but after I select submit in my form, all the files entered in the control will disappear.
If I click "browse", I get a dialog with the file browser, but the file loads correctly.
How to add a file upload control to your form and display a file browser dialog box and still work as intended.
source share