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

Sant_Singh_Rath
Level 7

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

Best regards,
Sant Singh Rathaur
4 REPLIES 4
SanfordWhiteman
Level 10 - Community Moderator

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

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

Sant_Singh_Rath
Level 7

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

Thanks, Sire! Here is the link for Marketo page where the form is not loading: https://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 

Best regards,
Sant Singh Rathaur
SanfordWhiteman
Level 10 - Community Moderator

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

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.

pastedImage_2.png

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:

pastedImage_1.png

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.

Sant_Singh_Rath
Level 7

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

Thanks, Sir! I know on this website there are so many unacceptable things as stakeholder was managing it by themselves and they kept adding whatever code they wanted without noticing any further circumstances. I am trying to fix the things one by one.

Thanks, again...  

Best regards,
Sant Singh Rathaur