Checking Postal Codes with JQuery
<p>I try to build a form which checks if an entered zip code matches a zip code in a predefined array. I don't use a DB, it's all very basic and hardcoded, but should be sufficient in this case.</p>

<p>The problem is that only the first zip-code in the array ('<em>83512</em>') works. If i am entering the second one ('<em>83533</em>') the code spits out "<em>no success</em>".</p>

<p>What am I doing wrong?</p>

<p>Thanks in advance.</p>

<p><strong>HTML:</strong></p>

<pre><code>&lt;form action="javascript:alert('success.');" id="checkplz"&gt;
    &lt;label for="plz"&gt;ZIP:&lt;/label&gt;
    &lt;input type="text" name="plz" id="plz" /&gt;
    &lt;button id="submit" &gt;Check!&lt;/button&gt;
    &lt;div id="output"&gt;&lt;/div&gt;
&lt;/form&gt;
</code></pre>

<p><strong>JQuery:</strong></p>

<pre><code>$(document).ready(function(){
    var list = ['83512','83533'];
    $("#checkplz").submit(function() {
        for (var i = 0; i &lt; list.length; i++) {
            if ($("#plz").val() == list[i]) {
                $("#output").append("&lt;strong class='success'&gt;success!&lt;/strong&gt;").show();
                return true;
            }
            $("#output").text("no success!").show().fadeOut(10000);
                return false;
        }
    });
});
</code></pre>
