동의 체크하고 버튼 누르면 특정url 로 이동을 하고 싶습니다.
본문
<form name="fregister" method="POST" action="javascript:fregister_submit(document.fregister);" autocomplete="off">
<p>
<input type=checkbox value=1 name=agree id=agree>
<label for=agree>내용에 동의합니다.</input>
<input type=submit>
</form>
<script language="javascript">
function fregister_submit(f)
{
if (!f.agree.checked) {
alert("동의 해야 넘어가집니다..");
f.agree.style.background="red";
return;
}
}
</script>
어디 부분에 링크를 넣어야 하는지 모르겠습니다....
답변 1
<form> ~ </form> 으로 처리된 경우에는.. form 의 action 속성에 다음 페이지 파일명(폼 처리 파일명)을 적어주면 됩니다.
<form name="fregister" method="post" action="next_file.php" onsubmit="return fregister_submit(this);" autocomplete="off">
<p>
<input type="checkbox" value="1" name="agree" id="agree">
<label for="agree">내용에 동의합니다
<input type="submit">
</form>
<script >
function fregister_submit(f){
if (!f.agree.checked) {
alert("동의 해야 넘어가집니다..");
f.agree.style.background="red";
return false;
}
return true;
}
</script>
위의 경우가 아닌 일반적인 자바스크립트에서 페이지 이동은 location.href 속성을 이용합니다.
location.href = "next_file.php";