Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does my Javascript code unexpectedly say my String value is Not a number (NaN)?
    text
    copied!<p>I am getting a javascript error Not a number "NaN" in the textarea field.</p> <p>I want to select a string from the autocomplete jqueryui and display the selected field into the textarea. Numeric values in the Json array display properly, but string values display NaN.</p> <p>This is My json array:</p> <pre><code> var financialClasses=[ "abc", "PQR", "xyz" ]; // these are the functions for selecting multiple values in the autocomplete textbox function split( val ) { return val.split( /,\s*/ ); } function extractLast( term ) { return split( term ).pop(); } // This function logs the selected field in the textarea function financialclasses_log(message) { $( "#financialclasses-log" ) .append( message+", ").prependTo( "#financialclasses-log" ); } $( "#financialclasses" )/* this function is required when selecting multiple values */ .bind( "keydown", function( event ) { if ( event.keyCode === $.ui.keyCode.TAB &amp;&amp; $( this ).data( "ui-autocomplete" ).menu.active ) { event.preventDefault(); } }) .autocomplete({ minLength: 0, source: function( request, response ) { // delegate back to autocomplete, but extract the last term response( $.ui.autocomplete.filter( financialClasses, extractLast( request.term ) ) ); }, focus: function() { // prevent value inserted on focus return false; }, select: function( event, ui ) { financialclasses_log( ui.item ? + ui.item.value: "Nothing selected, input was " + this.value ); 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( ", " ); $(this).val(""); return false; } }); // here is the html &lt;div id="financialclass" class="autocomplete_divs" class="ui-widget"&gt; &lt;fieldset style="padding:0px"&gt; &lt;a href="addlist.jsp" style="float:right; margin-right:5px"&gt;Add List&lt;/a&gt;&lt;br&gt; &lt;label for="financialclasses"&gt;&lt;/label&gt; &lt;input id="financialclasses" size="25"&gt; &lt;br&gt; &lt;textarea id="financialclasses-log" class="log" class="ui-widget-content"&gt;&lt;/textarea&gt; &lt;legend title="Financial Classes"&gt;&lt;b&gt;Financial Classes&lt;/b&gt;&lt;/legend&gt; &lt;/fieldset&gt; &lt;/div&gt; </code></pre> <p><a href="http://jsfiddle.net/pratik24/gEkWF/2/" rel="nofollow">http://jsfiddle.net/pratik24/gEkWF/2/</a></p>
 

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