다음 echo 문은 빈 텍스트 상자와 php를 사용하는 제출 단추를 만듭니다.제출시 유효성 입력 입력이 비어 있지 않음
echo"<td><form id=\"edit\" name=\"edit\" method=\"post\" action=\"../assets/modules/coursemanager/process.cm.php\" onsubmit=\"return check_edit();\">
<input type=\"text\" size=\"3\" id=\"edit_places\" name=\"edit_places\" value=\"\" />
<input type=\"hidden\" name=\"sid\" value=\"".$sid."\" />
<input type=\"submit\" name=\"Submit\" value=\"edit places\" /></form></td>";
위의 양식은 내가 사용하고있는 유효성 검사 JavaScript이지만 무시해도됩니다.
function check_edit(){
var notempty=document.forms["edit"]["edit_places"].value;
if(notempty==null || notempty==""){
alert("Please enter the new number of available places and try again");
return false;
}else{
return true;
}
}
누군가 내 오류를 표시 할 수 있다면 매우 감사 할 것입니다.
문제가 아닌지 확실하지 않지만'notempty == nul || notempty == ""''notempty == null || notempty == ""'. 또한 Javascript가 작동하는 방식 때문에 'null'과 '' ''을 처리하지만 '정의되지 않음', 'false'및 '0'도 처리하는 'if (! notempty)'가 더 간단합니다. 'null' /''''만 체크하고 싶다면'=='대신'==='를 사용해야합니다. – machineghost
세 번째 줄에 'null'이 잘못 표기되어 있습니다. –
아, 예. 조쉬에게 감사드립니다. 게시물에서 그 부분을 바로 잡았습니다. – Twobears