노드js·자바스크립트
제이쿼리로 입력폼의 빈값 체크하는 함수 입니다.
김일국
2014. 5. 16. 13:29
해당 html 내용에 nullChk_txt와 nullChk_chk 로 클래스명을 주고, 함수를 실행하는 구조 입니다.
<script type="text/javascript">
function submitForm()
{
var errorMessage = null;
var objFocus = null;
$(".nullChk_txt").each(function(){
if ($.trim($(this).val()).length == 0){
errorMessage = $(this).attr('name')+" 은 필수입력값입니다.";objFocus=$(this);
}
});
$(".nullChk_chk").each(function(){
if ($(this).prop('checked')==false){
errorMessage = $(this).attr('name')+" 은 필수선택값입니다.";objFocus=$(this);
}
});
if(errorMessage != null) {
alert(errorMessage);
objFocus.focus();
return false;
}
}
</script>