Set a file upload field to be a required part of form submission:
document.getElementById("myFile").required = true;
Click button to set the required property for the file upload field.
<!DOCTYPE html> <html> <body> <form action="/action_page.php"> Select a file: <input type="file" id="myFile" name="usr_file"> <input type="submit"> </form>/* ww w .ja v a2 s.c o m*/ <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { document.getElementById("myFile").required = true; document.getElementById("demo").innerHTML = "The required property was set."; } </script> </body> </html>