Need to force focus if there is an error

Need to force focus if there is an error

Hi,

Can someone help me edit this code that instead of hiding the submit button
 ($("#submit_button").css("display" , "none");) 

when there is an error, rather to just show the error message 

($('#tfa_4929-D').append("<div class='error' style='color:red;'>Invalid  number. One can only submit this form if this field is blank or it contains a valid  number.</div>");)

and force focus to the correct field that has the error?

Here is the snippet that I need edited.


jQuery(document).ready(function($) {
 
  $("input").on('keyup',  function(event) {

   $("body").find(".error").remove();
    
   Id = $('#tfa_4929').val();
   Id2 = $('#tfa_4939').val();
   Id3 = $('#tfa_4941').val();
    
    if(checkId(Id) != true ){

      $("#submit_button").css("display" , "none");
      $('#tfa_4929-D').append("<div class='error' style='color:red;'>Invalid  number. One can only submit this form if this field is blank or it contains a valid  number.</div>");
    }
    
        if(checkId(Id2) != true){
      $("#submit_button").css("display" , "none");
      $('#tfa_4939-D').append("<div class='error' style='color:red;'>Invalid number. One can only submit this form if this field is blank or it contains a valid number.</div>");
    }

   
        if(checkId(Id3) != true){
      $("#submit_button").css("display" , "none");
      $('#tfa_4941-D').append("<div class='error' style='color:red;'>Invalid  number. One can only submit this form if this field is blank or it contains a valid number.</div>");
    }
    

});