Disable submit if inputs empty jquery <p>Disclaimer: I know there are quite a few questions out there with this topic and it has been highly addressed, though I need assistance in my particular case.</p> <p>I am trying to check if the input values are empty on keyup then disable the submit button.</p> <p>My HTML snippet:</p> <pre><code>&lt;div class='form'&gt; &lt;form&gt; &lt;div class='field'&gt; &lt;label for="username"&gt;Username&lt;/label&gt; &lt;input id="username" type="text" /&gt; &lt;/div&gt; &lt;div class='field'&gt; &lt;label for="password"&gt;Password&lt;/label&gt; &lt;input id="password" type="password" /&gt; &lt;/div&gt; &lt;div class='actions'&gt; &lt;input type="submit" value="Login" /&gt; &lt;/div&gt; &lt;/form&gt; &lt;/div&gt; </code></pre> <p>I have used the example answer from <a href="http://stackoverflow.com/questions/5614399/disabling-submit-button-until-all-fields-have-values">here</a> with some modifications:</p> <pre><code>(function() { $('.field input').keyup(function() { var empty = false; $('.field input').each(function() { if ($(this).val() == '') { empty = true; } }); if (empty) { $('.actions input').attr('disabled', true); } else { $('.actions input').attr('disabled', false); } }); })() </code></pre> <p>Any help would be greatly appreciated!</p>