stopping form submit if the validation fails.

后端 未结 7 2251
青春惊慌失措
青春惊慌失措 2020-12-05 21:17

I am validating the dates in below function. If the validation fails, then the form should not get submitted. I tried returning false in form onsubmit but it still gets subm

7条回答
  •  攒了一身酷
    2020-12-05 22:03

    return is not going to stop the form from submit if its called in a subfunction e.g. compare(sDate, eDate)

    so change your function to this

    function dateCheck(e){
    
      var start = document.getElementById('name3').value;
      var end = document.getElementById('name4').value;
      if(compare(start, end)) {
        // no error submit i guess
        // return true ?
      } else {
        // error with date compare
        return false;
      }
      end.focus();
    
    }
    

提交回复
热议问题