#1
  1. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Nobbies beach, Gold Coast. It's beautiful.
    Posts
    2,574
    Rep Power
    171

    Jquery does not work as external file!


    Hello I use Jquery in this page page and it woks fine. For example the calendar, price range slider....

    Now I did all the HTML validations and took all the Jquery to an external file and none of the exterlans work here! For example the calendar, price range slider...You can see the script in the source :

    <script src="controller_js/controller_gallery_nd2.js"></script>


    What is going on? Howcome it only works when copy pasted directly in the page?

    Thank you.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    50
    Rep Power
    35
    Looks like you have some php code mixed in with your javascript, for example:

    Code:
    $(function() {
            var options = {
                range: true,
                min: 0,
                max: <?php echo $maximum_number;?>,
                values: [0, <?php echo $maximum_number;?>],
                slide: function(event, ui) {
                    var min = ui.values[0],
                        max = ui.values[1];
    
                    $("#amount").val("$" + min + " - $" + max);
                    showProducts(min, max);
                }
            }, min, max;
    Which was fine when your code was inline in gallery_nd2.php but now that you've move it out into controller_gallery_nd2.js it is being served as a plain text/javascript file and is no longer being executed by php. This is causing some errors to occur on the page and so is probably what is preventing things from working correctly.
  4. #3
  5. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Nobbies beach, Gold Coast. It's beautiful.
    Posts
    2,574
    Rep Power
    171
    Originally Posted by Edge360
    Looks like you have some php code mixed in with your javascript, for example:

    Code:
    $(function() {
            var options = {
                range: true,
                min: 0,
                max: <?php echo $maximum_number;?>,
                values: [0, <?php echo $maximum_number;?>],
                slide: function(event, ui) {
                    var min = ui.values[0],
                        max = ui.values[1];
    
                    $("#amount").val("$" + min + " - $" + max);
                    showProducts(min, max);
                }
            }, min, max;
    Which was fine when your code was inline in gallery_nd2.php but now that you've move it out into controller_gallery_nd2.js it is being served as a plain text/javascript file and is no longer being executed by php. This is causing some errors to occur on the page and so is probably what is preventing things from working correctly.
    Oh of course. I also have to move the php to the very top of the page i that one.

    Cheers

IMN logo majestic logo threadwatch logo seochat tools logo