How to resolve Uncaught reference error when attempting to call a JavaScript function -


i have c# mvc web application , trying organize java script . since moving below javascript view , adding folder keep getting "uncaught reference error addartist" while debugging in firefox. scripts worked fine when included on web page.

i reference jquery , script as:

<head>      <script src="/scripts/jquery-lib/jquery-1.10.2.js"></script>      <script src="/scripts/addartist.js"></script> </head> 

then here script:

(function() {        $(function() {         var addartist;         return addartist = function() {           var adddiv, artistval;           adddiv = $("#artistname");           artistval = $("#artistinput").val();           $(" <div id=\"artistname2\"><label>" + artistval + "</label></div>").appendto(adddiv);           return false;         };       });      }).call(this); 

*and here html:*

                                    <div id="artist"class="form-group">                                         @html.labelfor(m => m.artists, new { @class = "col-lg-2 control-label" })                                         <div class="container">                                             @html.textboxfor(m => m.artists, new { placeholder = "artist name",@class="form-control", id="artistinput"})                                               <img onclick="addartist()" id="plusartist" src="\content\bootstrap\img\plus-button.png" class="img-thumbnail"/>                                             @html.validationmessagefor(m => m.artists)                                         </div>                                           @*<button id="plusartist" onclick="addartist()">test</button>*@                                      </div>                                     <div id="artistname"><label></label></div> 

in script addartist function not exported. i'm not sure stylish way create addartist function, work:

var addartist= function() {       var adddiv, artistval;       adddiv = $("#artistname");       artistval = $("#artistinput").val();       $(" <div id=\"artistname2\"><label>" + artistval + "</label> /div>").appendto(adddiv);       return false;     }; 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -