0x800a138f - JavaScript runtime error: Unable to get property 'fn' of undefined or null reference

0

I am trying to do this example http://jsfiddle.net/pmrotule/w7aakdbb/54/

There I am getting this exception

0x800a138f - JavaScript runtime error: Unable to get property 'fn' of undefined or null reference. and 0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'multiselect' . It is throwing error at this point in bootstarp-multiselect.js

$.fn.multiselect = function(option, parameter, extraOptions) {
    return this.each(function() {
        var data = $(this).data('multiselect');
        var options = typeof option === 'object' && option;

        // Initialize the multiselect.
        if (!data) {
            data = new Multiselect(this, options);
            $(this).data('multiselect', data);
        }

        // Call multiselect method.
        if (typeof option === 'string') {
            data[option](parameter, extraOptions);

            if (option === 'destroy') {
                $(this).data('multiselect', false);
            }
        }
    });
};

My HTML code:

<script src="~/Scripts/bootstrap-multiselect.js"></script>
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<link href="~/Content/bootstrap-multiselect.css" rel="stylesheet" />
<script src="~/Scripts/bootstrap.js"></script>
<select id="ddlCars" multiple="multiple">
   <option value="Accord">Accord</option>
   <option value="Duster">Duster</option>
   <option value="Esteem">Esteem</option>
   <option value="Fiero">Fiero</option>
</select>
<script>
   $('#ddlCars').multiselect();
</script>

I am using ASP.NET MVC project in VS2013. There I am getting this exception I am very new to JS and BootStarp.

javascript
asp.net-mvc
twitter-bootstrap-3
multi-select

3 Answers

5

Correct the order of scripts, jQuery js should be the first to load because bootstrap.js and bootstrap-multiselect.js depends on jquery js.

<link href="~/Content/bootstrap-multiselect.css" rel="stylesheet" />
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/bootstrap.js"></script>
<script src="~/Scripts/bootstrap-multiselect.js"></script>
answered on Stack Overflow Mar 30, 2016 by Kartikeya Khosla • edited Mar 30, 2016 by Kartikeya Khosla
1

What the error says is that $ is not yet defined (during execution of bootstarp-multiselect.js), because you need to load jQuery first.

And since bootstrap-multiselect.js can depend on bootstrap, it doesn't harm to also load bootstrap.js before bootstrap-multiselect.js.

So:

<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/bootstrap.js"></script>
<script src="~/Scripts/bootstrap-multiselect.js"></script>
...
answered on Stack Overflow Mar 30, 2016 by huysentruitw • edited Mar 30, 2016 by huysentruitw
0

order of javascript file inclusion is wrong, jQuery file should be included first.

answered on Stack Overflow Mar 30, 2016 by Nishant Baranwal

User contributions licensed under CC BY-SA 3.0