테스트 사이트 - 개발 중인 베타 버전입니다

체크박스 동의 여부 스크립트 문의 채택완료

8년 전 조회 3,459

안녕하세요. 아래 처럼 소스를 짯는데 체크박스 부분만 얼럿창이 안되네요 ㅜ

고수님들 도와주삼요..

</p><p><form name="f1" method="post" enctype='multipart/form-data'></p><p>
</p><p>약관의 내용에 동의합니다.
<input type="checkbox" name="agree" value="1" id="agree"></p><p><input type="button" value="참가신청하기" onclick="form_Check();"></p><p>
</p><p></form></p><p>
</p><p>
</p><p>​</p><p><script>
function form_Check(){</p><p>
</p><p>if (!f.agree.checked) { 
            alert("약관 내용에 동의해주세요."); 
            f.agree.focus(); 
            return false; 
        } </p><p>
</p><p> if(f1.name.value == ''){
  alert("이름을 입력해주십시오.");
  f1.name.focus();
  return;
 }</p><p>
</p><p>.</p><p>.</p><p>.</p><p>
</p><p></script></p><p>
</p><p>
</p><p>
</p><p>

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

답변 2개

채택된 답변
+20 포인트

</p><p><form name="f1" method="post" enctype='multipart/form-data' onsubmit="form_Check()"></p><p>
</p><p>약관의 내용에 동의합니다.</p><p><input type="checkbox" name="agree" value="1" id="agree"></p><p><input type="submit" value="참가신청하기"></p><p>
</p><p></form></p><p>
</p><p>
</p><p>​</p><p><script></p><p>function form_Check(){</p><p><span style="white-space:pre">	</span>if (!f1.agree.checked) { </p><p><span style="white-space:pre">		</span>alert("약관 내용에 동의해주세요."); </p><p><span style="white-space:pre">		</span>f1.agree.focus(); </p><p><span style="white-space:pre">		</span>return false; </p><p><span style="white-space:pre">	</span>} </p><p><span style="white-space:pre">	</span>if(f1.name.value == ''){</p><p><span style="white-space:pre">	</span>  alert("이름을 입력해주십시오.");</p><p><span style="white-space:pre">	</span>  f1.name.focus();</p><p><span style="white-space:pre">	</span>  return false;</p><p><span style="white-space:pre">	</span> }</p><p>
</p><p>}</p><p>
</p><p>
</p><p></script></p><p>
</p><p>
</p><p>
</p><p>

로그인 후 평가할 수 있습니다

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

오타가 있네요

</p><p><code class="keyword" style="font-size: 14.004px; background-color: rgb(248, 248, 248); font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; margin: 0px !important; padding: 0px !important; border: 0px !important; outline: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; float: none !important; vertical-align: baseline !important; position: static !important; left: auto !important; top: auto !important; right: auto !important; bottom: auto !important; height: auto !important; width: auto !important; line-height: 1.8em !important; font-weight: bold !important; color: rgb(0, 102, 153) !important;">if</code><span style="font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace; font-size: 14.004px; background-color: rgb(248, 248, 248);"> </span><code class="plain" style="font-size: 14.004px; background-color: rgb(248, 248, 248); font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; margin: 0px !important; padding: 0px !important; border: 0px !important; outline: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; float: none !important; vertical-align: baseline !important; position: static !important; left: auto !important; top: auto !important; right: auto !important; bottom: auto !important; height: auto !important; width: auto !important; line-height: 1.8em !important;">(!f.agree.checked) {</code> </p><p><code class="plain" style="font-size: 14.004px; background-color: rgb(248, 248, 248); font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; margin: 0px !important; padding: 0px !important; border: 0px !important; outline: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; float: none !important; vertical-align: baseline !important; position: static !important; left: auto !important; top: auto !important; right: auto !important; bottom: auto !important; height: auto !important; width: auto !important; line-height: 1.8em !important;">

부분에 

f1이 되어야 할것 같구요

더 잘 작동하게 하시려면

</code></p><p>
</p><pre><p style="margin-left: 0px;">
<script>
function form_Check(){
    var f = document.f1;
    if (!f.agree.checked) { 
        alert("약관 내용에 동의해주세요."); 
        f.agree.focus(); 
        return false; 
    } 

    if (f.name.value == ''){              
       alert("이름을 입력해주십시오.");
       f.name.focus();
       return;
    }

.
.
.

</script></p></pre><div><span style="font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace; font-size: 14.004px; background-color: rgb(248, 248, 248);">
 
와 같이 f1을 f로 지정하시고
전부 f로 바라보게 하는것도 방법입니다.
document 바로 하위에 form의 name="f1" 을 가지는것을 지정할때 주로 사용합니다
가급적 중복되지 않는 이름을 사용하시는게 더 좋습니다.
로그인 후 평가할 수 있습니다

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

답변을 작성하려면 로그인이 필요합니다.

로그인
🐛 버그신고