custom JS in landing page forms

Subscribe
Anonymous
Not applicable

Our marketing department asked me to limit the number of checkboxes allowed to be chosen to 3. I can make it work from my development server, but when inserted into the template, it fails. I'm missing something very simple... I'm certain! Here is the code with a few parameters changed. Any help is appreciated! destinationmap is the name of all of the checkboxes.

<script src="//app-ab07.marketo.com/js/forms2/js/forms2.min.js"></script>

<form id="mktoForm_####"></form>

<script>MktoForms2.loadForm("//app-ab07.marketo.com", "###-###-###", ####, function(form) {

        // From here we have access to the form object and can call its methods

       var limit = 3;

       form.onValidate(function() {

       // Get the values

       var vals = form.vals();                              

       var kount = vals.destinationmap.length;

       if(kount > 3){

            alert('You may only choose up to three countries for which to receive a map.');

            form.submittable(false);             

       }     

  });      

});

</script>

Tags (2)
6 REPLIES 6
Anonymous
Not applicable

Hi Chris,

Are you using it Marketo page or in external page?. may i know what error you getting?

Anonymous
Not applicable

Hi Arunkumar. Thanks for getting back to me.

When I run the code on my server at the office, it works just fine. I'm not getting an error, but when I insert the code into a Marketo Landing Page, the script doesn't work and allows more than 3 checkboxes to be checked.

Chris

Anonymous
Not applicable

You added the form using Drag and drop in marketo or you have added the script only?

Anonymous
Not applicable

Actually, I don't know. The Marketing department built the form in Marketo and asked me to write the script. I'm going to have James in Marketing take a look.

Anonymous
Not applicable

If they dropped the form and also embedded the script, ask them to remove the dropped form in the marketo editor. I hope script alone is enough.

Anonymous
Not applicable

Hi Arunkumar,

This is James - Chris's colleague. I created the page using a guided landing page, and so the form was already an element on the page. I can certainly try creating a page using a different template to allow me to add the form via script alone. I'll let you know how we get on!

James