How to include custom JS in a Concrete5 page

Permalink
Sorry if the question is basic, but googling and binging and searching these forums haven't given me a working solution.

I have a html form with custom js for processing (see code below).
I'm using the Composer to add the code to the body section, using the html perspective.
At best, the form renders, but when I click the "Calculate" button, nothing happens. The browser console indicates that the function loan could not be found.
I've also noticed that the script tags are stripped when I re-enter the editor after saving and publishing; is that important/normal?
What am I missing/how do I fix this?
<div id="mortgageCalculator">
    <!-- Script by hscripts.com -->
    <script type="text/javascript">
        function checnum(as)
        {
            var dd = as.value;
            if(isNaN(dd))
            {
                dd = dd.substring(0,(dd.length-1));
                as.value = dd;
            }
        }
      function loan() {
            var a = $("#aa").val();
            var b = $("#bb").val();

 
MrKDilkington replied on at Permalink Reply
MrKDilkington
Hi cc667e11,

What version of concrete5 are you using?

"I'm using the Composer to add the code to the body section, using the html perspective."

To clarify, are you adding the code into the "rich text editor" text area in Composer?

Can you take a screenshot of how you set up your Composer and where you are adding your code, please.
cc667e11 replied on at Permalink Reply
Thanks for the quick reply though, even late on Independence Day!

Got my form and Js to work, after reading the documentation a little more closely. I used the HTML block instead of putting the code directly into the body via the Composer For future reference, I've copied the text from the documentation for future reference.

The HTML block gives you the ability to paste code directly into your page.
If you've got an embedded code or some javascript you just need to paste on the page, this is a great way to do it. If you've got some complicated HTML you've made in another program (like a big table layout) this is probably a better block to use than the content block.