Title: Javascript execution after successful upload
Last modified: April 1, 2019

---

# Javascript execution after successful upload

 *  Resolved [Cityproject](https://wordpress.org/support/users/nikpar/)
 * (@nikpar)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/javascript-execution-after-successful-upoload/)
 * Hello Nickola,
    I need to run a javascript that will do some changes to the image
   of the page after the file (image actually) will be uploaded successfully from
   the plugin. Is there an event or a listener to triger the script?
 * I noticed to an answer you provided about 8 months ago that you used “… if ( 
   $file[“upload_result”] == “success” …” in a php function but I cannot figure 
   out how i could use that in a javascript function. As an example. for another
   plugin I used “… $(‘.quform-form-9’).on(‘quform:successStart’, function () …”
   but the quform:successStart listener was in the plugin’s code.
 * Best regards,
    Nick Paraskevopoulos

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

 *  Plugin Author [nickboss](https://wordpress.org/support/users/nickboss/)
 * (@nickboss)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/javascript-execution-after-successful-upoload/#post-11382005)
 * Geia sou Nick,
 *  Use the following code to run the Javascript code defined in $changable_data[“
   js_script”]:
 *     ```
       if (!function_exists('wfu_after_upload_handler')) {
       	function wfu_after_upload_handler($changable_data, $additional_data) {
       		foreach ( $additional_data["files"] as $file ) {
       			if ( $file["upload_result"] == "success" || $file["upload_result"] == "warning" ) {
       				$filepath = $file["filepath"];
       				$url = str_replace(ABSPATH, site_url().'/', $filepath);
       				$changable_data["js_script"] = "
       					//custom Javascript code here without <script> tags
       				";
       				break;
       			}
       		}
       		return $changable_data;
       	}
       	add_filter('wfu_after_upload', 'wfu_after_upload_handler', 10, 2);
       }
       ```
   
 * So set in $changable_data[“js_script”] the code you want. I also provide the 
   URL of the image in a variable.
 * The code will run on user’s browser right after the file is uploaded.
 * Put the above code in functions.php file of your theme.
 * Filika
 * Nikos
 *  Thread Starter [Cityproject](https://wordpress.org/support/users/nikpar/)
 * (@nikpar)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/javascript-execution-after-successful-upoload/#post-11383325)
 * Wonderful, it worked great. You rock, thank you very much!
 *  Plugin Author [nickboss](https://wordpress.org/support/users/nickboss/)
 * (@nickboss)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/javascript-execution-after-successful-upoload/#post-11383385)
 * Ok thanks for letting me know.
 * Regards
 * Nickolas

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

The topic ‘Javascript execution after successful upload’ 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/)

## Tags

 * [javascript](https://wordpress.org/support/topic-tag/javascript/)

 * 3 replies
 * 2 participants
 * Last reply from: [nickboss](https://wordpress.org/support/users/nickboss/)
 * Last activity: [7 years, 2 months ago](https://wordpress.org/support/topic/javascript-execution-after-successful-upoload/#post-11383385)
 * Status: resolved