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,064
21년 전 조회 603
21년 전 조회 470
21년 전 조회 538
21년 전 조회 556
21년 전 조회 495
21년 전 조회 488
21년 전 조회 422
21년 전 조회 557
21년 전 조회 885
21년 전 조회 743
21년 전 조회 878
21년 전 조회 532
21년 전 조회 554
21년 전 조회 563
21년 전 조회 514
21년 전 조회 595
21년 전 조회 447
21년 전 조회 660
21년 전 조회 423