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

  • 11 August 2013
  • 4 replies
  • 256 views

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


4 replies

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.

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.

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.

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

Reply