jQuery: Simple Validate of a File Upload Field Programming 08 JUL 2009

Question:

How do I validate if a user has selected a file to upload before submitting my upload form?

Answer:

Simply check that it’s value contains something. In other words check:

$('#myFileInput').get(0).value
//or else in plain vanilla javascript check:
document.getElementById('myFileInput').value

Useful to remember.

jquery logo

Related Posts:

About Craig Lotter

Software developer, husband and dad to two little girls. Writer behind An Exploring South African. I don't have time for myself any more.