Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plug in does not load

Why does not my plug in load? The jquery and plug in links are referenced. The plug in is called .. .. Please help me find what I am missing in the code.

 <script src="~/Scripts/jquery-1.7.1.js"></script>
  <script src="~/Scripts/chosen.jquery.js"></script>


  <select class="chzn-select" tabindex="1" style="width:350px;" data- 
    placeholder="Choose a Country">
      <option value=""></option> 
      <option value="United States">United States</option> 
      <option value="United Kingdom">United Kingdom</option> 
      <option value="Afghanistan">Afghanistan</option> 
      <option value="Albania">Albania</option>                
   </select>

   <script>

   $(document).ready(function(){
       $(".chzn-select").chosen();
   });

   </script>

I am getting the firebug error:

TypeError: $(...).chosen is not a function

like image 771
EP2012 Avatar asked Jan 15 '23 03:01

EP2012


2 Answers

Reading the comments and searching for the related issue I found out that the reason is that because the jQuery was being included twice. Look at this.

I created this fiddle where I am including chosen from this cdn service.

If jquery is included only once than

$(".chzn-select").chosen();

should work fine.

EDIT:

Instead of using

$(document).ready(function(){
    $(".chzn-select").chosen();
});

try

$(document).bind("pageinit", function() {
    $(".chzn-select").chosen();
});
like image 103
Jehanzeb.Malik Avatar answered Jan 16 '23 20:01

Jehanzeb.Malik


Your jquery and/or chosen plugin does not seem to load.

Try replacing them with:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>
<script src="/scripts/chosen.jquery.js" type="text/javascript"></script>

Also make sure chosen.jquery.js is really included, by opening the url from your source. Or checking your network tab in firebug or any other developer console. If it shows a 404, your script isn't at the right location.

Also make sure your page layout is like this

<html>
    <head>
        <!-- your css files -->
        <link/>
    </head>
<body>
    <!-- Your html above javascript includes-->
    <select>
    ....
    </select>
    <!-- Inlcude your js files at the bottom -->
    <script src="bla.js" />
    <script>
        //your inline javascript goes below includes

    </script>
</body>

like image 40
Timmetje Avatar answered Jan 16 '23 21:01

Timmetje