2014-02-18 3 views
0

확인란의 유효성을 검사하는 폼을 만들려고합니다. 나는 새로운 페이지로 이동하기 전에 박스를 체크하고 submit 버튼을 눌러야한다는 생각이다. 그래서 나는 체크 박스를 가지고 있으며 그것을 검사 할 수있는 함수가 있지만 페이지를로드 할 수는 없다. 두 페이지를 여기에 로컬로 저장하고 올바른지, 그래서 그것은 유효성 검사 기능에 문제가 있어야합니다. 어떤 도움을 주셔서 감사합니다!확인란의 유효성을 검사하고 새 페이지에 연결

<!DOCTYPE html> 
<html> 
<head> 
<title>AcceptTerms</title> 
</head> 
<body> 
<h1>Before proceeduing you must agree to our terms and conditions.</h1> 
<br> 
<h3>Do you accept our terms?</h3> 
<form> 
<p><input type="checkbox" name="checkbox" value="Yes, I accept" />Yes, I accept</p> 
<input type="button" value="Submit" onclick="confirmTerms()"> 
</form>  
<br> 
<button onclick="openDecline()">Decline Terms</button> 
<script> 
function openDecline() 
{ 
window.open("declinepage.html"); 
} 
</script> 
<br>  

<script type="text/javascript"> 
function confirmTerms() { 
if (document.forms[0].checkbox.checked==false { 
alert("You did not select a box."); 
return false 
} 
if (document.forms[0].checkbox.checked) { 
window.location.href = "acceptpage.html"; 
} 
if (document.forms[0].checkbox.checked=false) { 
window.location.href = "declinepage.html"; 
} 
</script> 
</body>  
</html> 

답변

0

나는 나는 이것이 당신이 을 필요로하는 무슨 생각 .. 스크립트에 일부 변경을하고 확인란 여기

<!DOCTYPE html> 
<html> 
<head> 
<title>AcceptTerms</title> 
</head> 
<body> 
    <h1>Before proceeduing you must agree to our terms and conditions.</h1> 

    <br> 
    <h3>Do you accept our terms?</h3> 

    <form> 
     <p><input type="checkbox" id="check1" value="Yes, I accept" />Yes, I accept</p> 
     <input type="button" value="Submit" onclick="confirmTerms()"/> 
    </form> 
    <br> 
    <button onclick="openDecline()">Decline Terms</button> 
     <script> 
    function openDecline() { 
     window.open("declinepage.html"); 
    } 

    function confirmTerms() { 
     if (!(document.getElementById("check1").checked)) { 
      alert("You did not select a box."); 
      return false; 
     } 
     else{ 
      window.location.href = "acceptpage.html"; 
     }  
    } 
    function openDecline(){ 
     if(!(document.getElementById("check1").checked)) { 
      window.location.href = "declinepage.html"; 
     } 
    } 
     </script> 
</body>  
</html> 

에 대한 이드 그것은 보여야 Fiddle

+0

이것은 내가 필요한 것입니다! 도와 주셔서 감사합니다! 내가 어디에서 잘못되었는지 알고 싶습니다. 체크 박스에 대한 정보를 얻기 위해 getElementById 메소드를 추가 한 것 같습니다. 그 맞습니까? – user3247096

+0

@ user3247096 예 – Myth

0

입니다 설정 like :

<!DOCTYPE html> 
<html> 
<head> 
<title>AcceptTerms</title> 
</head> 
<body> 
<h1>Before proceeduing you must agree to our terms and conditions.</h1> 
<br> 
<h3>Do you accept our terms?</h3> 

<form> 
    <p><input type="checkbox" name="checkbox" value="Yes, I accept" />Yes, I accept</p> 
    <input type="button" value="Submit" onclick="confirmTerms()"> 
</form> 

<br> 
<button onclick="openDecline()">Decline Terms</button> 
<script> 
    function openDecline() 
    { 
    window.open("www.facebook.com"); 
    } 
</script> 
<br>  

<script type="text/javascript"> 
function confirmTerms() { 

if (document.forms[0].checkbox.checked==false) { 
document.write("Not Checked"); 
alert("You did not select a box."); 
return false; 
} 

if(document.forms[0].checkbox.checked) { 
document.write("Checked"); 
window.location.href = "www.google.com"; 
} 

} 
</script> 
</body>  
</html> 
관련 문제