Note that there are some explanatory texts on larger screens.

plurals
  1. POparseInt doesn't work
    primarykey
    data
    text
    <p>in my current source code textbox value is 1. when I try <code>alert(isNaN(obj.text())</code> it returns <code>false</code> that is expected but after parseInt when I write <code>alert(a);</code> it returns <code>NaN</code></p> <pre><code>minus.click(function () { var a = 1; if (!isNaN(obj.text())) a = parseInt(obj.text()); if (a &gt; 1) a -= 1; obj.text(a); }); </code></pre> <p>what is the problem?</p> <p>Edit: this is the full code:</p> <pre><code>&lt;input type="text" class="basket-txt" value="1" /&gt; jQuery.fn.basket = function (options) { var defaults = { } options = jQuery.extend(defaults, options); this.each(function () { var $this = $(this); $this.height(32).css({ 'line-height': '32px', 'font-weight': 'bold', 'width':'40px', 'text-align':'center', }); var tbl = $('&lt;table border="0" style="border-spacing:0px;float:left;"&gt;').appendTo($this.parent()); var tr1 = $('&lt;tr&gt;').appendTo(tbl); var plus = $('&lt;div class="basket-plus"&gt;'); $('&lt;td&gt;').append(plus).appendTo(tr1); $('&lt;td&gt;').append($this).appendTo(tr1); var minus = $('&lt;div class="basket-minus"&gt;'); $('&lt;td&gt;').append(minus).appendTo(tr1); var tr2 = $('&lt;tr&gt;').appendTo(tbl); $('&lt;td&gt;').appendTo(tr2); $('&lt;td&gt;').appendTo(tr2).append($('&lt;div&gt;').addClass('add-to-basket')); $('&lt;td&gt;').appendTo(tr2); $this.keypress(function (e) { if (e.which &lt; 48 || e.which &gt; 57) e.preventDefault(); }); minus.click(function () { var a = 1; if (!isNaN($this.text())) a = parseInt($this.text()); if (a &gt; 1) a -= 1; $this.text(a); }); plus.click(function () { var a = 1; if (!isNaN($this.text())) a = parseInt($this.text()); if (a &lt; 1000000) a += 1; $this.text(a); }); }); } </code></pre> <p><strong>actually I knew I could correct the code and it would work my concern was to understand why isNaN returns false but parseInt returns NaN</strong></p>
    singulars
    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.
 

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