How to submit form on selecting image in file select widget? I am using Drupal Form API to upload profile image for user.
I found two file upload widgets in FORM API:


'#type' =&gt; 'managed_file' &amp;
'#type' =&gt; 'file'


managed_file requires first selecting the file, then uploading the file and then submitting the form to change the image

file requires first selecting the file and then submitting the form to change the image

What I want to do is just when you select the image file and click ok in the file browser, the form should get submitted and image should be changed.

Is it possible using FORM API?
If not please recommend an alternative solution.
Of course it is possible. You need to take regular managed file and add some JavaScript to the file selection in it. To see how it is done, please see AutoUpload module:


  This module removes the extra button press and hides the "Upload" button via JavaScript for a quicker, automatic file upload. When JavaScript is not enabled, it falls back to the "Upload" button.


The most interesting is line 9, out of it's 22 lines of code:

$('.form-item input.form-file', context).change(function() {


And maybe simply using this module is all you really need?