Re: How to add onclick attribute to the submit button?

Anonymous
Not applicable

How to add onclick attribute to the submit button?

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> 
Tags (1)
2 REPLIES 2
Anonymous
Not applicable

Re: How to add onclick attribute to the submit button?

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 - Community Moderator

Re: How to add onclick attribute to the submit button?

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.