June 20, 201016 yr hi is there a way i can check if a file upload field is empty or not with javascript/jquery when the submit button is pressed?
June 20, 201016 yr Of course. Here's the solution using jQuery: <script type="text/javascript"> $(document).ready(function(){ $("#the_form").submit(function(){ if ($('[name=the_file_field]').val() == "") { /* Do something to make them notice the field is invalid */ return false; } }); }); </script> Use the above with this HTML: <form action="" method="post" id="the_form"> <!-- The rest of your form --> <input type="file" name="the_file_field" /> <!-- The rest of your form --> </form>
Create an account or sign in to comment