2014-02-13 5 views
0

등록 스크립트를 작성하려고하고 모든 양식 항목을 확인하거나 제출을 취소해야합니다. 많은 포럼과 많은 답변을 살펴본 결과 내 대답이 어떻게 다른지 보지 못했습니다. HTML 내가 제출을 클릭하고 항목이 충족되지 않을 경우, 양식이 아직 제출양식 제출 취소 자바 스크립트가 작동하지 않습니다.

function checkAll() 
{ 
if(usernameOK == true) 
{ 
    if(emailOK == true) 
    { 
     if(passwordOK == true) 
     { 
      return true; 
     } 
    } 
} 
$('#Error').fadeIn(100); 
return false; 
} 

<form onSubmit='checkAll()' method='post' action='mydestination.php'> 
<table> 
    <tr> 
    <td><input type='text' name='username' id='txtUsername' class='textboxLargeStyle' placeholder='Username' onChange='checkUsername("false")'/></td> 
    </tr> 
    <tr> 
    <td><input type='text' name='email' id='txtEmail' class='textboxLargeStyle' placeholder='Email Address' onChange='checkEmail()'/></td> 
    </tr> 
    <tr> 
    <td><input type='password' id='pwd1' name='password' class='textboxLargeStyle' placeholder='Password' onkeyup='checkPassword()'/></td> 
    </tr> 
    <tr> 
    <td><input type='password' id='pwd2' name='password2' class='textboxLargeStyle' placeholder='Re-type Password' onkeyup='checkPasswordMatches()'/></td> 
    </tr> 
    <tr> 
    <td><input type='submit' class='buttonLargeStyle' value='Sign Up'/></td> 
    </tr> 
    <tr> 
    <td colspan='2'><small id='Error'>Ensure you have all ticks before submitting! Hover over a cross to see the error.</small></td> 
    </tr> 
</table> 
</form> 

JAVASCRIPT.

답변

2

당신은 onsubmit 핸들러

<form onSubmit='return checkAll()' method='post' action='mydestination.php'> 
+0

이 완벽에서 checkAll에 의해 반환 된 false 값을 반환해야합니다. 항상 잊어 버리는 작은 것들. 고마워요. D –

0
function checkAll(e) 
{ 
    e.stopPropogation(); //Stops bubbling 
    e.preventDefault(); //prevents anything else that would happen from the click (submit) 

    if(usernameOK && (emailOK && passwordOK) { 
    e.currentTarget.submit();//Submits form 
    } 

    $('#Error').fadeIn(100); 
    return false; 
} 
관련 문제