Can someone tell me why this Javascript does not work with a published Forms 2.0 form? | Community
Skip to main content
January 22, 2015
Solved

Can someone tell me why this Javascript does not work with a published Forms 2.0 form?

  • January 22, 2015
  • 2 replies
  • 1049 views
I have tried this in both my template and on the landing page. I get the document ready alert but the second alert returns "undefined". I don't seem to be able to access anything from the DOM with forms 2.0 forms.
Can anyone point me in the right direction to do this?

<script type="text/javascript">// <![CDATA[
jQuery(document).ready(function(){
            alert("document ready called");
          
            alert(jQuery('.mktoForm').attr('height'));
});
// ]]></script>
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Kenny_Elkington
Hey Sharon,

We recommend using a callback from the whenReady function for these kinds of things like so:

<script>
MktoForms2.whenRead( function(form){
alert(jQuery('.mktoForm').attr('height'));
});
</script>

You can find more about the Forms 2 api here: http://developers.marketo.com/documentation/websites/forms-2-0/

2 replies

Kenny_Elkington
Adobe Employee
Kenny_ElkingtonAdobe EmployeeAccepted solution
Adobe Employee
January 22, 2015
Hey Sharon,

We recommend using a callback from the whenReady function for these kinds of things like so:

<script>
MktoForms2.whenRead( function(form){
alert(jQuery('.mktoForm').attr('height'));
});
</script>

You can find more about the Forms 2 api here: http://developers.marketo.com/documentation/websites/forms-2-0/
January 22, 2015
That worked. Thank you!!