jQuery testing presence of value in field not working properly
<p>I'm working on a project and have a jQuery event handler I made to try to detect the presence of user entered data in a field as it's being typed in. It kind of works with one weird side to it that has me a bit puzzled as to why this is happening.</p>

<p>The routine I wrote is this;</p>

<pre><code>$(document).ready(function() {
  $('#salary_bal').on('change blur keydown', function() {
    if($(this).val.length === 0 || $(this).val() === '') {
      setSubmitState('off');
    } else {
      setSubmitState('on');
    }
  });
});

function setSubmitState(state) {
  switch(state) {
    case 'on':
      $('#fsSubmit').attr('disabled', false);
      $('#fsSubmit').addClass('button');
      $('#fsSubmit').addClass('cursor');
    break;
    case 'off':
      $('#fsSubmit').attr('disabled', true);
      $('#fsSubmit').removeClass('button');
      $('#fsSubmit').removeClass('cursor');
    break;
  }
}
</code></pre>

<p>As you can probably guess by the setSubmitState calls, if the bound field does not have a value, it should disable the form's submit button.</p>

<p>Like I said, this is "sorta" working right. The snag is that it's actually acting like it's responding to the previous character keyed in rather than an newly keyed in character.</p>

<p>Here's the action sequences and their respective results;</p>

<ol>
<li>Enter a single 'x' into the field.
<ul>
<li>Submit button does not become enabled.</li>
</ul></li>
<li>Enter another 'x' in the field.
<ul>
<li>Submit button changes to enabled.</li>
</ul></li>
<li>Backspace and delete one 'x'.
<ul>
<li>Submit button remains enabled.</li>
</ul></li>
<li>Backspace again leaving field empty.
<ul>
<li>Submit button remains enabled.</li>
</ul></li>
<li>Backspace one more time.
<ul>
<li>Submit button changes to disabled.</li>
</ul></li>
</ol>

<p>I have been banging my head against a wall trying to debug this and am getting tired of spinning my wheels. (not to mention the headache from the wall) Can anyone offer a solution to this issue, please?</p>
