Form not loading when we added the javascript in richtext... | Community
Skip to main content
Sant_Singh_Rath
Level 6
Oct 7, 2019 10:16 AM UTC
Question

Form not loading when we added the javascript in richtext...

Hi There,

Hope all are doing well. I have experienced unusual behavior with the Marketo form today. We have added the javascript code inside rich-text and that was working completely fine until today.  

When I created a Marketo landing page and placed the form with javascript inside rich-text, form is not loading and when I removed that script, it's working fine.

Is there anyone else who is facing the same issue?

Or should I move the script into our server for the best experience? Please suggest.

Best,

Sant

4 replies

SanfordWhiteman
Level 10
Oct 7, 2019 12:40 PM UTC

You'd have to supply a URL. Can't troubleshoot your page without seeing it.

Translate
Sant_Singh_Rath
Level 6
Oct 7, 2019 4:38 PM UTC

Thanks, Sire! Here is the link for Marketo page where the form is not loading: myfuture.sae.edu/js-testing.html (when we edit the page it's visible)

However, the same form is added on the website page as well and working fine. website page URL: Enquire Now 

Translate
Best regards,Sant Singh Rathaur
SanfordWhiteman
Level 10
Oct 7, 2019 8:10 PM UTC

It's a clear race condition, because you're asynchronously injecting a (redundant) jQuery library and then trying to access it immediately. This doesn't happen on the other page because the jQuery library is also loaded earlier.

The best solution is of course to avoid using jQuery at all, since it distracts from learning real JS.

But if you must use jQuery, you still don't need to reload it in the Rich Text. The Forms 2.0 library already includes jQuery. 

So you can remove

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>‍

and use MktoForms2.$ instead of $.

As an aside, this is just terrible code:

If you're testing for the string "interactive", then test for the string "interactive"! Don't understand what would possess someone to look for the letters "in" anywhere in a string instead of the actual match. Such extreme "shortcuts" (which actually are bugs) are unacceptable on a professional site.

Translate