Javascript for loop

jymenn's Avatar

jymenn

10 Oct, 2015 12:36 AM

Hello, I recently ended up as a Cascade admin for my college and I'm relatively lost. I'm trying to get a javascript for loop working on a page, but it's rendering my less than character as < :

for (i = 0; i < data.response.award.length; i++)

I know that cascade tends to javascript in //<![CDATA[, which I believe tells the system to not escape characters? I'm typing this into my WYSIWYG (I'm assuming it's TinyMCE?) through the HTML button:

<script type="text/javascript">// <![CDATA[
function processJson(data) {
    text = ""
    for (i = 0; i < data.response.award.length; i++) {
//do some sutff
    }
    $('$x').html(text)
//alert(data.response.award[0].agency);
}
// ]]></script>

Any suggestions?

  1. 1 Posted by jymenn on 12 Oct, 2015 01:12 PM

    jymenn's Avatar

    Threw the js in a separate file and called it from page. Working now.

  2. 2 Posted by Ryan Griffith on 13 Oct, 2015 04:14 PM

    Ryan Griffith's Avatar

    Hi,

    Another way to accomplish this would be to use a #protect code section to ensure Cascade does not attempt to clean up invalid XML. For example:

    <script type="text/javascript"><![CDATA[#protect
    function processJson(data) { 
        text = "" 
        for (i = 0; i < data.response.award.length; i++) { 
    //do some sutff 
        } 
        $('$x').html(text) 
    //alert(data.response.award[0].agency); 
    } 
    #protect]]></script>
    

    Please let me know if you have any questions.

    Thanks!

  3. Tim closed this discussion on 30 Oct, 2015 03:24 PM.

Discussions are closed to public comments.
If you need help with Cascade CMS please start a new discussion.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

 

26 Aug, 2016 01:19 PM
25 Aug, 2016 03:02 PM
25 Aug, 2016 12:50 PM
24 Aug, 2016 08:43 PM
24 Aug, 2016 07:20 PM
21 Aug, 2016 01:20 PM