I tried it out and it looks like it's possible. Is there any reason I shouldn't do this?
Solved! Go to Solution.
There is no inherent problem with storing JS behaviors on the form. But realize the following:
Overall I've seen little reason to do this as opposed to serving forms-enhancing code separately, but you may have a niche case where it's useful.
Hi Eben
If your works well, there is not an issue. Only thing I have seen with more java script is, performance issues. Avoid having more code on forms, it may cause form to be loaded slowly also slow performance during data saving (submit click). Small amount of code should not have any issues.
Avoid having more code on forms, it may cause form to be loaded slowly
No, it won't. Any script that affects form behavior must be executed before the form is used, anyway.
also slow performance during data saving (submit click)
No.
There is no inherent problem with storing JS behaviors on the form. But realize the following:
Overall I've seen little reason to do this as opposed to serving forms-enhancing code separately, but you may have a niche case where it's useful.
Hi Sanford,
Thank you for the detailed information. I was tempted to use it for a form that's hosted by a partner so I don't have to reach out to them to add some javascript to populate a hidden field. But the form rarely gets changed, so I'm thinking I'll just put out a request to them to add the javascript. And if I want the ability to add javascript myself a better solution might be to ask them to include a script tag pointing to a location that I have access to.
Thanks again,
Eben
I think telling them to add something from the start like:
<script type="text/javascript" src="//your.example.com/forms/behaviors.js"></script>
is a good idea.
Then you can start it with just a commented line and add stuff later:
/* MktoForms2.whenReady() */
The more I think about this, as long as you duplicate the remote script include in both the RT area and the KL HTML, it might be quite convenient.
Another point which could be pro or con, depending on your goals: if you store JS behaviors on the form, the form must be approved in order for those behaviors to take effect, and when using Marketo LPs that means the hosting LP must also be reapproved. In contrast, if JS is stored on the LP itself (either Marketo or non-Marketo) then only that hosting LP needs to be pushed to production; if JS behaviors are stored in a separate file, only that file needs to be updated.
And -- maybe this is obvious -- if you store JS on the form, you make showing your code to others for troubleshooting more difficult. All of my forms demos show the code right in the main document so you can see what's going on.