Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript not executing when placed in external script file
    primarykey
    data
    text
    <p>I'm building an ASP.NET MVC site where I need a tag editor, similar to the one used on Stack Overflow. I've already looked up how to accomplish the necessary autocompletion with jQuery UI, but I've run into a problem: <strong>when I place the script in an external <code>.js</code> file, it doesn't execute</strong>.</p> <p>Here is my <code>test.html</code>:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;meta charset="utf-8"&gt; &lt;title&gt;Test&lt;/title&gt; &lt;script src="http://jqueryui.com/jquery-1.4.2.js"&gt;&lt;/script&gt; &lt;script src="http://jqueryui.com/ui/jquery.ui.core.js"&gt;&lt;/script&gt; &lt;script src="http://jqueryui.com/ui/jquery.ui.widget.js"&gt;&lt;/script&gt; &lt;script src="http://jqueryui.com/ui/jquery.ui.position.js"&gt;&lt;/script&gt; &lt;script src="http://jqueryui.com/ui/jquery.ui.autocomplete.js"&gt;&lt;/script&gt; &lt;script src="jquery.tagautocomplete.js"&gt;&lt;/script&gt; &lt;script&gt; $(function() { bindAutoTagComplete('#birds'); }) &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;label for="birds"&gt;Birds: &lt;/label&gt; &lt;input id="birds" size="50" /&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Here's <code>jquery.tagautocomplete.js</code>:</p> <pre><code>function bindAutoTagComplete(item, otherRootDomain) { function split( val ) { return val.split( / \s*/ ); } function extractLast( term ) { return split( term ).pop(); } $(item).autocomplete({ source: function( request, response ) { $.getJSON('http://jqueryui.com/demos/autocomplete/search.php', { term: extractLast( request.term ) }, response ); }, search: function() { // custom minLength var term = extractLast( this.value ); if ( term.length &lt; 2 ) { return false; } }, focus: function() { // prevent value inserted on focus return false; }, select: function( event, ui ) { var terms = split( this.value ); // remove the current input terms.pop(); // add the selected item terms.push( ui.item.value ); // add placeholder to get the comma-and-space at the end terms.push( "" ); this.value = terms.join( " " ); return false; } }); } </code></pre> <p><strong>What do you think may be causing this problem?</strong> I'm probably missing some closing parantheses/braces in the <code>.js</code> file...</p> <p><em>Thanks in advance!</em></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload