javascript - jQuery validation for empty textbox, and focus, disable button if validation false result -


i have more jquery validation ajax. want make validation :

  1. if textbox empty, disable button.
  2. if while validation database false, focus textbox , disable button.

and make code far jquery validation :

$("#button_submit").attr("disabled", "true"); $("#accessories_sheet").keyup(function()         {             var accessories_sheet = $("#accessories_sheet").val();             var acc_no = $("#acc_no").val();             var revision = $("#revision").val();             var combine_part = $("#combine_part").val();              if(accessories_sheet.length >= 16)             {                 $("#status_acc").html('<div class="pos_loader">processing...</div>');                  $.ajax(                 {                       type: "post",                       url: "check_accs.php",                       data: 'accessories_sheet='+ accessories_sheet +'&acc_no='+ acc_no +'&revision='+ revision +'&combine_part='+ combine_part,                     success: function(msg)                     {                           $("#status_acc").ajaxcomplete(function(event, request, settings)                         {                              if(msg == 'ok')                             {                                  $("#accessories_sheet").removeclass('object_error'); // if necessary                                 $("#accessories_sheet").addclass("object_ok");                                 $(this).html('<div class="notify success">ok</div>');                                 $("#box_pn").focus();                             }                             else                               {                                   $("#accessories_sheet").removeclass('object_ok'); // if necessary                                 $("#accessories_sheet").addclass("object_error");                                 $(this).html(msg);                                 $("#accessories_sheet").focus();                                 $("#accessories_sheet").select();                                 $('#button_submit').attr("disabled", true);                             }                            });                     }                  });              }             else             {                 $("#status_acc").html('<div class="notify errors">accessories sheet length 16 characters.</div>');                 $("#accessories_sheet").removeclass('object_ok');                 $("#accessories_sheet").addclass("object_error");             }         });          $("#box_pn").keyup(function()         {             var box_pn = $("#box_pn").val();             var combine_part = $("#combine_part").val();             var revision = $("#revision").val();              if(box_pn.length >= 12)             {                 $("#status_box_pn").html('<div class="pos_loader">processing...</div>');                  $.ajax(                 {                       type: "post",                       url: "check_box_pn.php",                       data: 'box_pn='+ box_pn +'&combine_part='+ combine_part +'&revision='+ revision,                     success: function(msg)                     {                           $("#status_box_pn").ajaxcomplete(function(event, request, settings)                         {                              if(msg == 'ok')                             {                                  $("#box_pn").removeclass('object_error'); // if necessary                                 $("#box_pn").addclass("object_ok");                                 $(this).html('<div class="notify2 success">ok</div>');                                 $("#pack_label_pn").focus();                             }                             else                               {                                   $("#box_pn").removeclass('object_ok'); // if necessary                                 $("#box_pn").addclass("object_error");                                 $(this).html(msg);                                 $("#box_pn").focus();                                 $("#box_pn").select();                                 $('#button_submit').attr("disabled", true);                             }                            });                     }                  });              }             else             {                 $("#status_box_pn").html('<div class="notify2 errors">box p/n length 12 characters.</div>');                 $("#box_pn").removeclass('object_ok');                 $("#box_pn").addclass("object_error");             }         }); 

and html textbox :

<form action="" method="post" autocomplete="off"> <input type="text" name="accessories_sheet" class="input_2" maxlength="16" id="accessories_sheet" onkeyup="javascript:this.value=this.value.touppercase();"/>  <td><input type="text" name="box_pn" class="input_2" maxlength="12" id="box_pn" onkeyup="javascript:this.value=this.value.touppercase();"/></td>  <input type="submit" value="submit" id="button_submit"/> 

any advice guys ? please, need help.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -