function validator(field_value, field) {
var name = document.getElementById('facility_Name').value;
var region = document.getElementById('facility_Region').value;
var state = document.getElementById('facility_State').value;
var county = document.getElementById('facility_County').value;
if (name == null || name == "") {
$("p#validator_error").append('<a href="#Facility_Details">Click here complete the <i>Name</i> field</a>');
$('#validation_modal').modal('show');
return false;
}
if (region == null || region == "") {
$("p#validator_error").append('<a href="#Facility_Details">Click here complete the <i>Region</i> field</a>');
$('#validation_modal').modal('show');
return false;
}
if (state == null || state == "") {
$("p#validator_error").append('<a href="#Facility_Details">Click here complete the <i>State</i> field</a>');
$('#validation_modal').modal('show');
return false;
}
if (county == null || county == "") {
$("p#validator_error").append('<a href="#Facility_Details">Click here complete the <i>County</i> field</a>');
$('#validation_modal').modal('show');
return false;
}
return true;
}
$('button#submitbutton').click(function() {
window.console.log('upload started');
//Check for Facility Details
return validator();
// then do more stuff including an Ajax call
});
이것은 간단한 검증 기능이어야합니까? 네 개의 필드 중 하나가 상자에 입력되지 않으면 매우 잘 작동합니다. 그건 문제가되지 않는 것 같습니다. 그러나 모든 필드가 입력되면 스크립트는 "return validator();"에서 중단됩니다. 어떤 종류의 오류도 발생시키지 않거나 스크립트의 나머지 부분을 완료하지 않습니다. "validator();"사용 어느 쪽도 작동하지 않습니까?Javascript return true not working/breaking script
또는 오류가 발생. 콘솔 확인 했니? JSFiddle에서이 문제를 재현 할 수 있습니까? –
왜 디버거를 넣고 단계를 밟아야합니까? –
'function validator (field_value, field)'에서 매개 변수를 제거하십시오. – aldrin27