Customizing Forms 2.0 with Jquery - late loading | Community
Skip to main content
Brennan_McAdam2
New Participant
April 10, 2015
Solved

Customizing Forms 2.0 with Jquery - late loading

  • April 10, 2015
  • 11 replies
  • 6506 views
I have been experimenting with creating dynamic sections of a landing page based on the selection of from a select menu.  I finally figured out that I was having problems between when Jquery was ready and when the form actually loaded.  In the end, I ended up explicitly adding the Form2.js in the top of my html block to get the MktoForms2.whenReady to properly call.  However, I am wondering if anyone solved this differently as a hate loading a script in twice.
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 Brennan_McAdam2
Found an even better solution.

Jquery is loading first as it is declared in the header.  As the Forms2.js is placed inline (after the header), I modifed the call to first check jQuery is ready, then check that the form is loaded to begin processing. 

//Attach change of select to display
    $(document).ready(function() {  //switched this to the top
        MktoForms2.whenReady(function (form){  //once jquery is ready, wait for the form
            $("#repurpose8").change( function(){
                changeLoc($(this).children('option:selected').index());
         });
        });
    });

11 replies

SanfordWhiteman
New Participant
April 10, 2015
The goal isn't entirely clear (sorry!) without example code/URL.

Try to create an example of code that triggers the failure (rather than code you fixed with a workaround) and post the URL.