Search code examples
javascriptvalidationonblurinput-type-file

Validate input type=file with onBlur


I'm able to use onBlur to validate type=text or textarea inputs, however I haven't been able to get the same to work for type=file.

This works:

<input type='text' name='sometextfield' size=30 class='input' onBlur="alert('Frell me dead, it works!');"

This does not (no error):

  <input type='file' name='file_upload' size=30 class='input' onBlur="alert('Frell me dead, it works!');"> 

What is the trick to validating type=file input boxes, on the fly? I'd like to do this in vanilla Javascript. I'm testing with Chrome 17.0.963.56 and Firefox 10.0.2 under Ubuntu.

Thanks for tips/pointers.


Solution

  • Try using the onchange-Event:

    <input type="file" name="file_upload" size="30" class="input" onchange="alert('Frell me dead, it works!');">
    

    Demo: http://jsfiddle.net/TimWolla/azvGP/