0

I call this function at the end of my HTML file - its basically just some fancy menu stuff from a tutorial I found online. The javascript (included below) is never called for some reason. I even tried to add an alert() to confirm this and I never see the alert popup so I know its not being called, but the file does exist on my server in that location.

Any thoughts?

<script type="text/javasvcript" src="js/filestorage.js" />

filestorage.js

/**
 * On DOMReady initialize page functionality
 */
$(document).ready(function(){

    // Test we load this file
    alert("READY!");

    //Add functionality into the menu buttons
    prepareMenu();
});

/**
 * Prepares the menu buttons for selecting
 * filetypes
 * @return NULL
 */
function prepareMenu()
{
    $("#menu li").click(
        function () {
            $("#menu li").each(
                function(){
                    $(this).removeClass("active");
                }
            );
            $(this).addClass("active");
            HideFiles($(this).children().html());
        return false;
    });
    //Select the first as default
    $("#menu li:first").click();
}


/**
 * Shows only the selected filetypes
 * @param selector
 * @return bool
 */
function HideFiles(selector)
{
    //show all files
    if(selector === "All files")
    {
        $("#files > li").show();
        return true;
    }
    else
    {
        //show only the selected filetype
        $("#files > li").hide();
        $("#files > li." + selector).show();
        return true;
    }
}
mattdonders
  • 1,328
  • 1
  • 19
  • 42
  • There is some confusion about self-closing script tags. I would recommend to never use them. Always you a separate closing tag. You can find further information here: http://stackoverflow.com/questions/69913/why-dont-self-closing-script-tags-work – Alex Jan 12 '13 at 15:56

1 Answers1

5

You have a typo in your type attribute, which probably is the reason the script is not being loaded. The script element also have to have a closing script tag.

This:

<script type="text/javasvcript" src="js/filestorage.js" />

Should be this:

<script type="text/javascript" src="js/filestorage.js"></script>

Or even this, since JavaScript is the default type:

<script src="js/filestorage.js"></script>
Christofer Eliasson
  • 32,939
  • 7
  • 74
  • 103
  • The last suggestion `` worked for me. I corrected the typo and it still didn't work but removing the type worked perfectly fine. Thanks - will accept as soon as Stackoverflow allows. – mattdonders Jan 12 '13 at 15:48
  • 2
    @mattdonders, `script` also can't be shortened a la ``, as in the your code. I know Christofer corrected that, but I thought it useful to point out too. – Jared Farrish Jan 12 '13 at 15:48
  • What's the reason for not allowing `` to be shortened a la `` though? – mattdonders Jan 12 '13 at 15:49
  • @JaredFarrish Thanks, I've updated my answer to clarify that. – Christofer Eliasson Jan 12 '13 at 15:49
  • 1
    @mattdonders - It's the specs. See http://www.w3.org/TR/html-markup/script.html#script-tags You'd have to ask W3C what the reasoning is here. Also, faux `/>` are almost always unnecessary in HTML5. It's sort've a legacy of people using XHTML doctypes unreasonably. Seriously, that `/` is superfluous and should be omitted with HTML5 doctype (which you should also be using, most likely). – Jared Farrish Jan 12 '13 at 15:50