title: How to disable an element based on ajax error respond
body: <p>I've <code>form</code> with single input field <code>name</code> and with jquery i'm checking the name availability before submit and it gives either error message if didn't passed the check or gives message <code>correct</code> if passed the check out.</p>
  
  <p><strong>Now my question</strong> i wonder if this code can be adjusted so that it disable <code>submit</code> in case it didn't passed the availability check</p>
  
  <p></p>
  
  <p>or whatever so that it prevent clicking on submit button if didn't passed availability check.</p>
  
  <p><strong>I'm using the following</strong></p>
  
  <p><strong>Form Code</strong></p>
  
  <pre><code>&lt;SCRIPT type="text/javascript"&gt;
  
  $(document).ready(function(){
  $("#name").change(function() {
  var usr = $("#name").val();
  
  if(usr.length &gt;= 4){
  $("#status").html('&lt;img src="loader.gif" align="absmiddle"&gt;&amp;nbsp;Checking availability...');
  
      $.ajax({
      type: "POST",
      url: "check.php",
      data: "name="+ usr,
      success: function(msg){
  
     $("#status").ajaxComplete(function(event, request, settings){
  
      if(msg == 'OK'){
          $("#username").removeClass('object_error'); // if necessary
          $("#username").addClass("object_ok");
          $(this).html('&amp;nbsp;correct');
      }else{
          $("#username").removeClass('object_ok'); // if necessary
          $("#username").addClass("object_error");
          $(this).html(msg);
      }
     });
   }
    });
  }else{
      $("#status").html('&lt;font color="red"&gt;The name should have at least 4 characters.&lt;/font&gt;');
      $("#username").removeClass('object_ok'); // if necessary
      $("#username").addClass("object_error");
      }
  });
  });
  &lt;/SCRIPT&gt;
  
  &lt;div id='myform'&gt;
  Name &lt;input type="text" name="name" id="name"&gt;&lt;div id="status"&gt;&lt;/div&gt;
  &lt;br /&gt;
  &lt;input id="submit" type="submit" name="Submit" value="Submit"&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>~ thanks for help</p>