javascript로 HTML 양식의 유효성을 검사하려고하는데 경고가 표시되지 않아 checkSubmit() 함수가 호출되지 않는다고 생각했습니다. 그러나 기능 시작 부분에 추가 경고를 추가 한 후에는 실제로 실행되지만 첫 번째 조건을 확인한 후에는 더 이상의 경고가 표시되지 않습니다.조건 확인 후 경고 양식이 유효하지 않음
<script language="javascript" type="text/javascript">
function checkSubmit() {
alert("Hello from Javascript!");
if (document.getElementById("user").value.toString.length <1) {
alert("Please enter a user name.");
return false;
}
if (document.getElementById("location").value.toString.length <1) {
alert("Please enter a location.");
return false;
}
if (document.getElementById("depart").value.toString.length <1) {
alert("Please enter a department.");
return false;
}
if (document.getElementById("category").value.toString.length <1) {
alert("Please enter a problem type.");
return false;
}
if (document.getElementById("info").value.toString.length <1) {
alert("Please enter a problem description.");
return false;
}
alert("Hello from Javascript2!");
return true;
}
</script>
<form name="submit" type="submit" method="POST" onsubmit="return checkSubmit();">
[...]
<input type="submit" name="submit" value="Submit" >
</form>
나는 (내가 돌이켜에서 명백 할 것이다 확신) 실수를하지 않는 한, 거기에 조건이 참 또는 거짓 경우 두 번째 경고에 관계없이, 팝업 안?
콘솔에 오류가보고됩니까? 어쩌면 당신의 컨트롤 중 하나를 찾지 못할 수도 있습니다 ... – Paddy
값이 정의되지 않은 것과 같은 오류가 발생했습니다. –
아하. 첫 번째 입력 상자에 "id ="태그가 없습니다. 그러나 이제는 반대의 문제가 있습니다. ID가 "user"인 상자에 텍스트가있는 경우에도 사용자 이름을 입력하라는 경고가 나타납니다. – CCKx