Title: Run JavaScript On Submission?
Last modified: August 24, 2016

---

# Run JavaScript On Submission?

 *  [Narthur](https://wordpress.org/support/users/narthur/)
 * (@narthur)
 * [11 years ago](https://wordpress.org/support/topic/run-javascript-on-submission/)
 * I’m trying to fire a Google Analytics event on form submission. I tried putting
   some JavaScript in the thank you message, but it seams to run before the user
   submits the form.
 * Is there anyway I can tie some JavaScript to form submission?
 * [https://wordpress.org/plugins/usernoise/](https://wordpress.org/plugins/usernoise/)

Viewing 1 replies (of 1 total)

 *  Thread Starter [Narthur](https://wordpress.org/support/users/narthur/)
 * (@narthur)
 * [11 years ago](https://wordpress.org/support/topic/run-javascript-on-submission/#post-6147054)
 * I tried this:
 *     ```
       jQuery(document).on('click','#un-feedback-submit',function() {
       	console.log('Ow!');
       });
       ```
   
 * Then I realized the form is in an iframe, so that doesn’t work.
 * I tried this in my theme’s functions:
 *     ```
       function trackFeedbackSubmission() {
       	echo '<script type="text/javascript">
       		ga("send","event","form","contact");
       		console.log("Submission tracking attempted");
       	</script>';
       }
       add_action('un_feedback_created','trackFeedbackSubmission');
       ```
   
 * Which results in this error in the JavaScript console on form submission:
 * `SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON
   data`

Viewing 1 replies (of 1 total)

The topic ‘Run JavaScript On Submission?’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/usernoise_b8babb.svg)
 * [Usernoise modal feedback / contact form](https://wordpress.org/plugins/usernoise/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/usernoise/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/usernoise/)
 * [Active Topics](https://wordpress.org/support/plugin/usernoise/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/usernoise/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/usernoise/reviews/)

 * 1 reply
 * 1 participant
 * Last reply from: [Narthur](https://wordpress.org/support/users/narthur/)
 * Last activity: [11 years ago](https://wordpress.org/support/topic/run-javascript-on-submission/#post-6147054)
 * Status: not resolved