How do I access this variable outside of this jquery loop?
<p>I have a simple jquery loop that goes through my form and </p>

<ol>
<li>sees if there is empty fields. </li>
<li>If any are empty, mark them with an 'empty' class and </li>
<li>then create a 'error' variable</li>
</ol>

<p>Basically:</p>

<pre><code>// check all the inputs have a value...
$('input').each(function() {

    if($(this).val() == '') {

        $(this).addClass('empty');
        var error = 1;

    }   

});
</code></pre>

<p>This works a charm. However, as my code continues, I can't seem to access that 'error' variable... as though it is locked inside the each loop. With the following code being right after the .each() loop, I never get my_error_function() to fire, even though I know that criteria 1 and 2 are working.</p>

<pre><code>if(error == 1) {

    my_error_function();

} else {

    my_non_error_function();

}
</code></pre>

<p>How do I access this variable so I can use its result elsewhere in the code?</p>
