Unusual javascript behavior when trying to re-enable submit button
===

I'm writing a small script to perform a regex validation. If the regex doesn't match, I disable the submit/"Next" button. It works fine, but I want to enable the submit/"Next" button if nothing is entered into the given text field. I have a function that looks like this:
 
    function functionname( code, tograb ){
        $.ajax({
                url : "{% url survey.views.ajax %}",
                data: {
                'r_code': code,
                'qid': '{{ question.id }}',
                'other_text': tograb.value,
                'csrfmiddlewaretoken': '{{ csrf_token }}'
          }, success: function(html){          
            if (html != "OK") {
              $('#Next').attr('disabled', true);
              $(#'span' + String(code)).html(html);
            } else {
              $('#Next').removeAttr('disabled');
               $(#'span' + String(code)).html("");
            }
          }
         });

        if (tograb.value.length == 0) {
              console.log("removing attribute");
              console.log(tograb.value.length);
              $('#Next').removeAttr('disabled');
        }
    };

The corresponding HTML looks like so:

      <input type="text" name="1" value = ""
      id = "other_text1"
      onkeyup="functionname('1', this)"
      /> 

This seems to work great for everything that works with a string length of anything over 1, but if if I delete everything in the text field, it doesn't work. Actually, it seems to work for half a second in that it re-enables the submit button, but then it disables the button again.

Looking at Firefox's debug console, I see the following:

    [14:02:26.757] GET http://myurl/survey/ajax?r_code=1&qid=9&other_text=d&   
    csrfmiddlewaretoken=m9s5BxbOeqDEheQyQmTIGzCrMbX56e8y [HTTP/1.1 200 OK 16ms]
    [14:02:28.826] removing attribute @ http://myurl/survey/6:27
    [14:02:28.829] 0 @ http://myurl/survey/6:28
    [14:02:28.833] GET http://myurl/survey/ajax?r_code=1&qid=9&other_text=& 
    csrfmiddlewaretoken=m9s5BxbOeqDEheQyQmTIGzCrMbX56e8y [HTTP/1.1 200 OK 13ms]

So it appears that two AJAX calls are being made, although I'm not sure why. Can someone explain this behaviour to me or show where I'm going wrong? Any feedback would be much appreciated!