Title: Widget Admin Forms and Javascript enqueuing
Last modified: August 30, 2016

---

# Widget Admin Forms and Javascript enqueuing

 *  [Neil Hillman](https://wordpress.org/support/users/neilh/)
 * (@neilh)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/widget-admin-forms-and-javascript-enqueuing/)
 * Hello, I am authoring a WP Widget plugin, and have run into a problem. My Widget’s
   Admin Form is quite involved, and uses an external javascript file to manipulate
   fields, collapse sections, etc. This external javascript is enqueued into the
   Widget Admin Panel like this:
 *     ```
       function enqueue_admin_scripts() {
         wp_register_script('mp3-admin-script', plugins_url('assets/js/wp-mp3-admin.js' , __FILE__ ), array( 'jquery' ));
         wp_enqueue_script('mp3-admin-script');
       }
       add_action('admin_enqueue_scripts','enqueue_admin_scripts');
       ```
   
 * This works fine initially, but when you make a change to the Widget’s Admin Form
   and click the “Save” button, the page is reloaded but WITHOUT any of the JavaScript.
 * If I refresh the page, the javascript is loaded again and resumes working, but
   each time the Widgets’ changes are saved, the javascript stops functioning.
 * Any ideas why ‘admin_enqueue_scripts’ doesn’t get executed after a widget is “
   Saved”?
 * Thanks for looking!

Viewing 1 replies (of 1 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/widget-admin-forms-and-javascript-enqueuing/#post-6712436)
 * The entire Widget Admin Panel reloads? That sounds odd already. I’m pretty sure
   all the default widgets save via AJAX and never trigger a reload, only the related
   HTML is updated via jQuery.
 * My guess is something is causing a JS error when you save your widget form. It
   may not even be your widget, perhaps there’s a name collision with another plugin
   or your theme. Have you checked your browser console for JS errors after a save?
   That would explain why JS no longer works.

Viewing 1 replies (of 1 total)

The topic ‘Widget Admin Forms and Javascript enqueuing’ is closed to new replies.

## Tags

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

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 1 reply
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [10 years, 6 months ago](https://wordpress.org/support/topic/widget-admin-forms-and-javascript-enqueuing/#post-6712436)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
