Note that there are some explanatory texts on larger screens.

plurals
  1. POPerplexing Javascript Integer comparison bug
    primarykey
    data
    text
    <p>This is probably a really simple thing but I can't for the life of me figure out or find anything remotely like the issue. I'm fairly new to Javascript and I'm doing some simple form validation on HTML fields. The two problems at hand are these:</p> <pre><code> if(minSquare.search(intCheck) == -1 || minSquare &lt; 500 || minSquare &gt; 5000 || minSquare &gt; maxSquare) { errorPrint.innerHTML += "Incorrect minimum square feet amount &lt;br /&gt;"; errors++; } if(maxSquare.search(intCheck) == -1 || maxSquare &gt; 5000 || maxSquare &lt; 500) { errorPrint.innerHTML += "Incorrect maximum square feet amount &lt;br /&gt;"; errors++; } </code></pre> <p>minSquare/maxSquare are the values taken from the HTML fields. As you can see the square feet values (in a real estate setting) are supposed to be between 500-5000 and have to be an integer. The logic is there, but every time I submit the form, the error for incorrect minimum square feet prints if the value is <strong>below 1,000 despite the lower limit being 500.</strong> This is the same case for another pair of fields in that if the value is below 100,000, it won't print despite its own lower limit being 30,000.</p> <p>For some reason when I enter 500 for the minimum amount and 5000 for the maximum amount (the proper range), it will submit no problem. But if I enter say, 501 and 5000 it will throw an error for the minimum value. I have no idea why this is happening. I don't think it's a browser issue; tried on both Chrome and Firefox, same problem. Any help appreciated; the more stupid the problem the quicker I can close this up =)</p> <p><strong>EDIT:</strong> Fixed the problem. Knew it was simple. As per advice below, I just needed to parse the inputs and then I needed to get rid of the RegExp search method that would only work if the variable being searched is a string. Thanks to those who replied.</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.
    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