Exit the javascript code when the validation failed -


i need exit javascript code when validation failed. @ moment having right error message when validation failed javascript code continue running. please find code below. thanks

var compplanid=1; var component=2; var tierno=3; var startdate=4; var enddate=5; var tiermin=6; var tiermax=7; var rate=8; var invalidflag = 0; var blanktextbox = '';  function datecheck() {     var startdateform= document.getelementbyid('tbltarget').rows[1].cells[startdate].getelementsbytagname('input')[0].value;      var enddateform= document.getelementbyid('tbltarget').rows[1].cells[enddate].getelementsbytagname('input')[0].value;      var edate = new date(enddateform);     var sdate = new date(startdateform);      if(startdateform== blanktextbox || enddateform == blanktextbox || sdate> edate)     {         alert("please ensure end date greater or equal start date.");     invalidflag = 1;         }    } 

// check if pk row not empty

function checkpkrow() {     var compplanidform= document.getelementbyid('tbltarget').rows[1].cells[compplanid].getelementsbytagname('select')[0].value;    if(compplanidform== blanktextbox)   {     alert("please ensure primary key not empty");     invalidflag = 1;    }  }  function submit()  {      invalidflag = 0;     checkpkrow();     datecheck();     

//call submit function if validation true.

    if(invalidflag == 0 )     {      $('button_submit').click();      alert('the new rate submitted');      }  } 

change code

function datecheck() {     var startdateform= document.getelementbyid('tbltarget').rows[1].cells[startdate].getelementsbytagname('input')[0].value;     var enddateform= document.getelementbyid('tbltarget').rows[1].cells[enddate].getelementsbytagname('input')[0].value;     var edate = new date(enddateform);     var sdate = new date(startdateform);     if(startdateform== blanktextbox || enddateform == blanktextbox || sdate> edate)     {         alert("please ensure end date greater or equal start date.");         return false;     }       return true;         }  function checkpkrow() {     var compplanidform= document.getelementbyid('tbltarget').rows[1].cells[compplanid].getelementsbytagname('select')[0].value;     if(compplanidform== blanktextbox)     {         alert("please ensure primary key not empty");         return false;     }     return true; }  function submit()  {     if(checkpkrow() &&  datecheck())     {         $('button_submit').click();          alert('the new rate submitted');     } } 

Comments