Disable submit button based on text input conditions

Disable submit button based on text input conditions

Hi

I have a simple website set up, 1 text input and 1 submit button. I have jQuery code in place to make it so, that the submit button is disabled until I have input at least 3 characters in the text input. That works as expected, but I have 2 little problems I have trouble of fixing.

Here is the HTML:
<input type="text" name="search_text" /> <input type="submit" value="Search" />

Here is the jQuery:
<script> $(document).ready(function()
{
      $('input[type="submit"]').attr('disabled','disabled');
      $('input[type="text"]').keyup(function()
      {
            if($(this).val().length > 2)
            {
                  $('input[type="submit"]').removeAttr('disabled');
            }
      });
});
<script>
The problem I have is this:
1. When deleting text from the input box, the submit button does not get disabled when text string in input box gets below 3 characters.
2. When clicking on the submit button and getting desired results from postback, the submit button gets disabled, even if the text in input box is still there.

Any help is most welcome. If you need more detailed info just ask.

Regards,
Gunnar