Title: Detect upload status in javascript
Last modified: October 20, 2016

---

# Detect upload status in javascript

 *  [jlarysz](https://wordpress.org/support/users/jlarysz/)
 * (@jlarysz)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/detect-upload-status-in-javascript/)
 * I am using wfu in an admin page to upload files. The page is generated on-the-
   fly and the upload is triggered in javascripts with the code fragment:
 * var elem = document.getElementById(“upload_1”);
    if (typeof elem.onclick == “
   function”) { elem.onclick.apply(elem); }
 * on the input object (id=”upload_1″)that is the submit button. The upload works,
   but how do I test for failure in javascript?

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [nickboss](https://wordpress.org/support/users/nickboss/)
 * (@nickboss)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/detect-upload-status-in-javascript/#post-8332837)
 * You can implement wfu_after_upload filter. This filter runs after upload has 
   finished. In this filter you can check if the file has succeeded or not. The 
   filter outputs Javascript code. So, you can execute custom javascript code depending
   on the result.
 * You can get instructions on how to use the filter in this link: [https://www.iptanus.com/filters-and-actions-of-wordpress-file-upload-plugin/](https://www.iptanus.com/filters-and-actions-of-wordpress-file-upload-plugin/).
   Please note that you need to implement wfu_after_upload filter, not wfu_after_file_upload.
 * Nickolas
 *  Thread Starter [jlarysz](https://wordpress.org/support/users/jlarysz/)
 * (@jlarysz)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/detect-upload-status-in-javascript/#post-8333967)
 * Thanks. I will try this.
 *  Thread Starter [jlarysz](https://wordpress.org/support/users/jlarysz/)
 * (@jlarysz)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/detect-upload-status-in-javascript/#post-8336952)
 * I’m still struggling; I think it’s ignorance. I have installed the filter mentioned
   above, but I can’t figure out how to get to the data in $changed_data returned
   by the filter.
 * The first wfu form is instantiated with this code:
 * `<?php echo do_shortcode('[wordpress_file_upload uploadid=1 uploadpath="uploads/
   ASNYjournals" uploadtitle="Locate Journal in PDF Format" uploadpatterns="*.pdf,*.
   PDF" userdata="true" userdatalabel="Media Date in YYY-MM-DD format|t:text|s:left
   |r:1|a:0|p:inline|d:/Media Title|t:text|s:left|r:1|a:0|p:right|d:" ]'); ?>`
 * The submit button set up by this code has id=upload_1, so the upload is triggered
   with this:
 *     ```
       var elem = document.getElementById("upload_1");
       	   if (typeof elem.onclick == "function") { ret = elem.onclick.apply(elem); console.log(ret);}
       ```
   
 * The return object “ret” does not exists, no matter what I try. This is driving
   me nuts!
    -  This reply was modified 9 years, 7 months ago by [jlarysz](https://wordpress.org/support/users/jlarysz/).
 *  Plugin Author [nickboss](https://wordpress.org/support/users/nickboss/)
 * (@nickboss)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/detect-upload-status-in-javascript/#post-8337701)
 * As an initial check to verify that the filter works put the following code in
   your functions.php file (or any other way you use to implement filters):
 *     ```
       if (!function_exists('wfu_after_upload_handler')) {
       	function wfu_after_upload_handler($changable_data, $additional_data) {
       		$changable_data['js_script'] = 'console.log("check");';
       		return $changable_data;
       	}
       	add_filter('wfu_after_upload', 'wfu_after_upload_handler', 10, 2);
       }
       ```
   
 * This will generate a “check” message in your browser’s console after upload (
   either successful or not). If it works, then I will tell you how to check for
   successful file upload.
 * Nickolas

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Detect upload status in javascript’ is closed to new replies.

 * ![](https://ps.w.org/wp-file-upload/assets/icon-256x256.png?rev=3252590)
 * [Iptanus File Upload](https://wordpress.org/plugins/wp-file-upload/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-file-upload/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-file-upload/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-file-upload/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-file-upload/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-file-upload/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [nickboss](https://wordpress.org/support/users/nickboss/)
 * Last activity: [9 years, 7 months ago](https://wordpress.org/support/topic/detect-upload-status-in-javascript/#post-8337701)
 * Status: not resolved