ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Javascript parameters seem to disappear

April 20, 2011 10:01am

Subscribe [2]
  • #1 / Apr 20, 2011 10:01am

    thisconnect.be

    73 posts

    Hi,

    I have a little bit of javascript for a jquery calendar-popup in my template.

    All goes well as long as the site is in debug mode.
    When I place the debugmode off, the script gets parsed differently.

    with

    $config['debug'] = "1";

    the script is:

    $(document).ready(function() {
                $("#date_from").datepicker({ dateFormat: "yy-mm-dd" });
                $("#date_to").datepicker({ dateFormat: "yy-mm-dd" });
            });

    with

    $config['debug'] = "0";

    the script is:

    $(document).ready(function() {
                $("#date_from").datepicker();
                $("#date_to").datepicker();
            });

    Now I want the script to be like in the debug version, but I don’t want the debug version to be on.
    What could I do?

  • #2 / Apr 20, 2011 10:53am

    Mark Bowen

    12637 posts

    First question would be why not leave the debugger on if it all works in that way?

    It is a known side-effect of having the debug set to 0 that Javascript can break in that way.

    You could however try placing line breaks at the curly braces and see if that helps :

    $(document).ready(function() {
                $("#date_from").datepicker({
    dateFormat: "yy-mm-dd"
    });
                $("#date_to").datepicker({
    dateFormat: "yy-mm-dd"
    });
            });

    That or try the hidden configuration variable in your config.php file :

    $config[‘protect_javascript’] = ‘y’;.

    What is happening here is that ExpressionEngine is seeing the braces and thinking that it is the start and end of a custom variable and so is trying to parse them as such. Hopefully one of the methods above might help out though.

    Hope that helps a bit.

    Best wishes,

    Mark

  • #3 / Apr 20, 2011 11:21am

    thisconnect.be

    73 posts

    Putting the line breaks at the curly braces does the trick.
    Putting the hidden config-variable “$config[‘protect_javascript’]” to “y” did not help when everything was on 1 line.

    Thanks!

  • #4 / Apr 20, 2011 11:38am

    Mark Bowen

    12637 posts

    Ah glad that got it working for you.

    As an aside though I’m not too sure why you didn’t want the debug preference set to 1 as it won’t do anything untoward so if that’s an option it might be nicer in the long run so that the scripts are easier to read.

    That’s entirely down to you of course though.

    Best wishes,

    Mark

  • #5 / Apr 20, 2011 11:46am

    Lisa Wess

    20502 posts

    Hey thisconnect.be, Mark is correct about the debug - we always recommend keeping that to 1, see this page in the user guide.

    Tip: We recommend always keeping this Debug Preference set to “1: PHP/SQL error messages shown only to Super Admins.” This may greatly reduce the time needed to troubleshoot issues as you will receive an error instead of a blank screen.

    Furthermore, for those utilizing Javascript that may resemble EE code, including curly brackets, this setting must be 1 in order for the Javascript to function, or ExpressionEngine will hide Javascript output believing it to be an error.

    In any case, I see you said “did not work” - at this point, are things working or did you still need assistance? 

    Thank you!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases