admin管理员组

文章数量:1387346

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.

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.

Share Improve this question edited Mar 7, 2012 at 18:58 a coder asked Mar 7, 2012 at 18:52 a codera coder 7,66921 gold badges86 silver badges137 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 5

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/TimWolla/azvGP/

本文标签: javascriptValidate input typefile with onBlurStack Overflow