Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Run JavaScript on Form Button Click If I Can't Modify The Form HTML

11:52 pm on Nov 6, 2014 (gmt 0)

Senior Member

WebmasterWorld Senior Member planet13 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:June 16, 2010
posts: 3828
votes: 31

Hi Everyone:

Is it possible to run some javascript (Adwords tracking code) on a Form submit button if I am not able to directly modify the html code for the form itself?

I CAN put javascript in the head of the page, or right before the closing body tag as well. Just not in the form itself.

The input code that is presently there is this:

<input class="et_pb_contact_submit" type="submit" value="Submit">

It is an Ajax form, so it doesn't go to a different page.

Here is the google conversion code:

<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 123456789;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "fbfbfb";
var google_conversion_label = "abcdefghijklmnop";
var google_remarketing_only = false;
/* ]]> */
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//www.googleadservices.com/pagead/conversion/123456789/?label=abcdefghijklmnop&amp;guid=ON&amp;script=0"/>

Thanks in advance.

I would really appreciate it too if when you answer, you write it as if you were speaking to someone who has little to no knowledge of javascript... which is pretty much me.
5:30 pm on Nov 13, 2014 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member whoisgregg is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Dec 9, 2003
votes: 0

Google Analytics allows you to send a custom "page view" event and override what URL is tracked. That looks like:

ga('send', 'pageview', '/this/is/not/a/real/url');

You would add this code to the javascript that is already overriding the form's submit event. If you are using jQuery that might look like this:

$( "#id-of-form" ).submit(function( event ) {
// track the event in GA
ga('send', 'pageview', '/ajax/form-submitted');

// rest of your code here...