Ninja Forms
Adding Javascript onSubmit action with Ajax forms (3 posts)

  1. pidginbil
    Posted 3 years ago #

    I'm currently configured to "Submit via Ajax." which is my preferred user experience. This means that I need to add a javascript onsubmit action to call Google analytics to track successful submissions in my goal funnel.

    If its possible to add an onsubmit action to the Ninja Forms Lite form tag, how do I do it?

    If it isn't possible, do I have any alternatives to deselecting "sumbit via Ajax" and creating a "success" page?


  2. kstover
    The WP Ninjas
    Plugin Author

    Posted 3 years ago #

    Hey pidginbil,

    You can do that in your own JS file, you just want to add an action to the "onclick" event of the submit button ID for your form.

  3. pidginbil
    Posted 3 years ago #

    Thanks Kevin ... I'm a little bit outside my comfort zone with JavaScript, so please help me out a bit if you can.

    button field ID: 9
    Using Inspect element, the Button HTML is:

    <input id="ninja_submit" name="ninja_submit" type="submit" value=" Submit " class=" ">

    the JavaScript I'd like to call is for google analytics:

    onsubmit="pageTracker._trackPageview('/pagename'); return false;"

    Where pageTracker._trackPageview is defined elsewhere on the page:

    <script type="text/javascript">
    var pageTracker = _gat._getTracker("UA-######-#");

    I do know how to add a javascript snippet to a wordpress page. What this untrained noob don't understand is how to wrap the onsubmit event in a way that ties it to the button ID.



Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Ninja Forms
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic