How to add onclick attribute to the submit button? | Community
Skip to main content
March 13, 2015
Question

How to add onclick attribute to the submit button?

  • March 13, 2015
  • 2 replies
  • 2375 views
I am trying to validate two email fields to make sure they are the same. I already have the folowing code on the page in a custom HTML block but I need to know how I add an onclick function to the submit button. There doesn't seem to be a way to add code to an actual form or submit element.
 
<script type="text/javascript"> 
function checkEmail(email1,email2) { 
   var e1 = document.getElementById('email1').value; 
   var e2 = document.getElementById('email2').value; 

   if (e1 != e2) { 
      return true; 
   } 
   else 
   { 
     alert('Plerase verify the email address!'); 
    return false; 
   } 
</script> 
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

2 replies

March 13, 2015
Hi,

There is some documentation on Marketo's Developer site about how to manipulate Form code. In order to add custom behavior you need to embed the Form 2.0 code on page and inject your custom script into it (all outlined in the documentation below).

I would recommend looking at #9 on the link below, it gives an example of validation on submit.
http://developers.marketo.com/documentation/websites/forms-2-0/
 
SanfordWhiteman
Level 10
March 13, 2015
As @Max S says, hook the onValidate event.

Another simple, runnable example here.

Note the Marketo Forms 2.0 object model/API is an enhanced wrapper around a real HTML <FORM>.  This is great because it allows you to use standard <FORM> behaviors (such as the native onSubmit event) and interrogate the form element in the DOM -- if absolutely necessary. However you should strive to use the supported Forms 2.0 API everywhere you can to avoid confusion.