wow맨

라디오 버튼 필수 체크 하기 좀..

아래와 같이 했는데. 상관없이 그냥 넘어 가네요...
어느 부분이 틀렸는지...
라디오 버튼 입니다..

<Script language="javascript">
<!--
function check(){
//주문자 성명 입력란 공백 검사
if (document.form1.che_01.value==""){
alert("주문자 성명을 입력하세요");
document.form1.che_01.focus();
return true;
}
if (document.form1.che_02.value==""){
alert("주문자 성명을 입력하세요");
document.form1.che_02.focus();
return true;
}

</script>

<form name="form1" method="post" action="check_update.php">
<input type="radio" name="che_01" value="1"><br>
<input type="radio" name="che_01" value="0"><br>
<input type="radio" name="che_02" value="1"><br>
<input type="radio" name="che_02" value="0"><br>

<input type="submit" name="Submit" value="전송" onclick="check();">

</form>
필요 없는것 빼고 필수 소스만 넣습니다.

이렇게 했는데.. 않되네요.. 부탁 드리겠습니다.. (__)
|

댓글 4개

zzzz님의 날카로운 지적.. 감사합니다.
true 가 조금 걸리네요. ^^;;


<Script language="javascript">
<!--
function check(){
//주문자 성명 입력란 공백 검사
if (!document.form1.che_01.checked){
alert("주문자 성명 1 을 선택하세요");
document.form1.che_01.focus();
return false;
} else if (!document.form1.che_02.checked){
alert("주문자 성명 2 을 선택하세요");
document.form1.che_02.focus();
return false;
}
return true;
}
//-->
</script>

<form name="form1" method="post" action="check_update.php" onsubmit='return check(this);'>
<input type="radio" name="che_01" value="1"><br>
<input type="radio" name="che_02" value="1"><br>
<input type="submit" name="Submit" value="전송">
</form>
다음처럼 해보세요.
그리고 주의할 점은 radio의 경우 name을 하나를 두어서 checked 이면 1을 그렇지 않으면 값이 없는것으로 판단하시어 처리하시면 되겠습니다.

<Script language="javascript">
<!--
function check(){
//주문자 성명 입력란 공백 검사
if (!document.form1.che_01.checked){
alert("주문자 성명을 선택하세요");
document.form1.che_01.focus();
return true;
}
if (!document.form1.che_02.checked){
alert("주문자 성명을 선택하세요");
document.form1.che_02.focus();
return true;
}
}
//-->
</script>

<form name="form1" method="post" action="check_update.php">
<input type="radio" name="che_01" value="1"><br>
<input type="radio" name="che_02" value="1"><br>

<input type="submit" name="Submit" value="전송" onclick="check();">

</form>
<Script language="javascript">
function check(){
if (document.form1.che_01.value==""){
alert("주문자 성명을 입력하세요");
document.form1.che_01.focus();
return false;
}
if (document.form1.che_02.value==""){
alert("주문자 성별을 입력하세요");
document.form1.che_02.focus();
return false;
}
}
</script>

<form name="form1" method="post" action="check_update.php" onsubmit='return check(this)'>
성명:<input type="text" name="che_01"><br>
성별:<input type="text" name="che_02"><br>
<input type="submit" name="Submit" value="전송">
</form>

참조 하세요..
댓글을 작성하시려면 로그인이 필요합니다. 로그인

그누3질답

+
제목 글쓴이 날짜 조회
21년 전 조회 1,033
21년 전 조회 561
21년 전 조회 428
21년 전 조회 503
21년 전 조회 526
21년 전 조회 449
21년 전 조회 458
21년 전 조회 379
21년 전 조회 527
21년 전 조회 842
21년 전 조회 709
21년 전 조회 839
21년 전 조회 502
21년 전 조회 516
21년 전 조회 525
21년 전 조회 473
21년 전 조회 570
21년 전 조회 409
21년 전 조회 616
21년 전 조회 389
🐛 버그신고