How do I add an onclick javascript event to the submit button on my landing page?


#1

How do I add an onclick javascript event to the submit button on my landing page?


#2

Hi Wyatt - you will need to place that snippet of code into the Javascripts section of your page (learn more about how to do this here.)

The code itself will need to refer to the submit button via the button’s ID. To find out what the ID of any element you have in the page is, simply click to select them in the page builder and then look under the Advanced Properties in the Properties tab on the right of the builder.


#3

Exactly how do I get the code to refer to the button’s ID. I have pasted the javascript and found the ID of the element I want it to refer to.


#4

Hey James - it’s tough with 3rd party code as there’s such a huge variety out there, but typically, you could associate your script with a button click by using a bit of jquery. There may be someone in the Unbounce community who could help you come up with the required code. Sorry we can’t be more help with this one.


#5

Hi James,

I had the same question few weeks ago while I was trying to add some custom Google Analytics tracking: I came up with something like that:

$(document).ready(function() {

("a#PUT-YOUR-BUTTON-CLASS").each(function() { var href = (this).attr(“href”);
var target = (this).attr("target"); var text = (this).text();
$(this).click(function(event) {
event.preventDefault();

>>> Put your Javascript on click event <<<<

setTimeout(function() { .
window.open(href,(!target?"_self":target));
},300);
});
});

You also need to tick the jquery box in the Unbounce “Manage Javascript” window.

I’m not a dev, so I’m not sure it works but it could help you. It’s something I found in here http://www.lunametrics.com/blog/2013/…

Marc


#6