Skip to main content
December 3, 2015
Question

Form button - on click event

  • December 3, 2015
  • 1 reply
  • 3133 views

Hi All,

Our web developers have asked me to insert a script into a form button, on click event. It relates to a data layer regarding GA and tracking.

This is the code:

onclick="dataLayer.push({ 'car_enquiry_type': "'" +vehicleIntendedFor.value+"'"  });"

Can this be done and if so where would it be inserted?

Thanks

Matt

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

SanfordWhiteman
Level 10
December 3, 2015

Do you actually have a form button as an element other than the Submit button?

Where in the form flow is this supposed to happen? (Hint: is it supposed to be after the form is successfully submitted?)

December 3, 2015

Hi Mate,

From what I understand, we use marketo forms and the css is modified to accommodate our brand. This is supposed to fire after form submit.

Im wondering if it can be added to the CSS code somehow.

Not sure pondering....

SanfordWhiteman
Level 10
December 3, 2015

What they probably want is:

MktoForms2.whenReady(function(form){

     form.onSubmit(function(form){

          dataLayer.push({ car_enquiry_type : "'" + form.getValues().vehicleIntendedFor + "'" });

     });

});

Should be aware that if you end up using the Forms 2.0 API in other ways, you'll need to consolidate your custom code in one place.