I want to include a small amount of JavaScript code in a particular snippet-powered page, and was pleased to discover that there is a MODx function (
regClientStartupScript (the link is to the Revo version of the documentation, as I couldn’t find the corresponding page for Evo)) which you can use in a snippet which will let you insert a <script> element into the document <head> (because <script> within the <body> is apparently not permitted in XHTML 1.0, and I’d like to stay valid).
So far, so good, but I need to include " onload=myFunction()" in the <body> tag in order to trigger my code (or possibly I need to rewrite my JavaScript code so that this is not necessary, but I’m no real JavaScript expert. What my code needs to do is set the ’display’ attribute of a particular form input field when the page loads, based on the value of a particular radio button elsewhere in the form. The only ways that I’m aware of being able to do this are either via onload, or via an in-<body> script just after the input field in question).
Is there a similar MODx function that would allow me to tweak the body tag from within a snippet in this way?
The only other alternative I can think of would be to add a Template Variable in the template for this page, but I
really don’t want to do this, as the page template is the same as used by most pages on the site and I don’t want to make such a TV available to other users or have to create a new template. (If there’s a way to make a TV available to a template, but only when a page is part of a particular Resource Group, then perhaps that might be a possibility?)
Thanks for any advice!