2011-12-04 8 views
3

すべてのテキストフィールドが正しく検証された場合にのみ、ボタンを表示するコードを作成する際に問題が発生します。私はページが開くときにボタンを隠しています(これを行うにはCSSを使うことができますが、機能を試してみることです)、フィールドが正しいときにボタンを表示したいと思います。私は成功のオプションを使用しようとしていますが、何かが記入される直前にボタンを表示しています。助言がありますか?jqueryでエラーがないか確認する方法.validate()

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> 
<script type="text/javascript" src="js\jquery.validate.js"></script> 
<script> 
$(document).ready(function(){ 
var submit = false; 
$(".btn").hide(); 
$("#submission").validate({ 
    rules: { 
     appSize: { 
     required:true, 
     max:12 }, 
     appName: { 
     required:true, 
     rangelength:[4,9] }, 
     appPrice: { 
     required:true, 
     min:.99, 
     max:3.99 }, 
     email: { 
     required:true, 
     email:true } 
    }, 

    messages: { 
     appSize: { 
     required: "App Size is a required field"}, 
     appName: { 
     required: "App Name is a required field", 
     rangelength: "The name must be between 4 and 9 characters" }, 
     appPrice: { 
     required: "App Price is a required field", 
     min: "Price must be .99 or greater", 
     max: "Price must be less than 3.99" }, 
     email: { 
     required: "email is a required field", 
     email: "You must enter a valid email address" }, 
     success: submit = true 

    }, 
    errorElement: "div", 




}); 
if(submit) 
    $(".btn").show(); 
$(".btn").click(function() { 

    alert("Data is Valid, Thanks for your submission");  
    }); 
}); 

</script> 
</head> 
<body> 
<form id="submission" method="post" action="#"> 
    <h1>Apple iPhone App Contest Submission Page</h1> 
    <div id="theForm"> 
     <div> 
       <label for="appSize">What is the file size in KB?</label> 
       <input name="appSize" type="text" id="fileSize" class="required error"></input> 
     </div> 
     <br /> 
     <div> 
       <label for="appName">What is the App Name?</label> 
       <input name="appName" type="text" id="appName" class="required error"></input> 
     </div> 
     <br /> 
     <div> 
       <label for="appPrice">What is the App Price? $</label> 
       <input name="appPrice" type="text" id="appPrice" class="required error"></input> 
     </div> 
     <br /> 
     <div> 
       <label for="email">Submitters Email Address</label> 
       <input name="email" type="text" id="email" class="required error"></input> 
     </div> 
     <br /> 
     <input type="button" class="btn" value="Submit"></input> 
    </div> 
</form> 
</body> 
</html> 

答えて

0

私は多くの助けを得ることができなかったので、私は実際に元のものを回避する必要がありました。ここに私の最終的なプロジェクトのビルドです:

<!DOCTYPE html> 
<html lang="en"> 
<head> 
<meta charset="utf-8"> 
<meta name="generator" content="CoffeeCup HTML Editor (www.coffeecup.com)"> 
<meta name="created" content="Thu, 01 Dec 2011 17:34:38 GMT"> 
<meta name="description" content=""> 
<meta name="keywords" content=""> 
<style type="text/css"> 
    h1 { 
    text-align:center; 
    background: #7AC5CD; 
    -moz-border-radius: 7px; 
    border-radius: 7px; 
    -moz-box-shadow: 5px 5px 5px #000; 
    -webkit-box-shadow: 5px 5px 5px #000; 
    box-shadow: 5px 5px 5px #000; 
    background: -moz-linear-gradient(top, #55aaee, #003366); 
    background: -webkit-gradient(linear, left top, left bottom, from(#55aaee), to(#003366)); 
    color: #000000; 
    height: auto; 
    padding: 5px;} 
    form { 
    background-color:#faefae; 
    -moz-border-radius: 7px; 
    border-radius: 7px; 
    -moz-box-shadow: 5px 5px 5px #000; 
    -webkit-box-shadow: 5px 5px 5px #000; 
    box-shadow: 5px 5px 5px #000; } 
    body { 
    background-color:#7AC5CD; } 
    .required { 
    border:inset; 
    position:absolute; 
    left:200px; 
    -moz-border-radius: 7px; 
    border-radius: 7px; 
    -moz-box-shadow: 5px 5px 5px #000; 
    -webkit-box-shadow: 5px 5px 5px #000; 
    box-shadow: 5px 5px 5px #000; } 
    .btn { 
    position:absolute; 
    left:600px; 
    top:120px; 
    width:125px; 
    height:50px; 
    font-size:larger; 
    -moz-border-radius: 7px; 
    border-radius: 7px; 
    -moz-box-shadow: 5px 5px 5px #000; 
    -webkit-box-shadow: 5px 5px 5px #000; 
    box-shadow: 5px 5px 5px #000; } 
    div.error { 
    font-size:large; 
    color:red; 
    font-family:arial; 
    font-style:italic;} 
    .images { 
    alignment-adjust:absolute; 
    position:absolute; 
    text-align:center; 
    left:450px; 
    background:#7AC5CD; 
    background-color:#7AC5CD;} 
</style> 
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> 
<script type="text/javascript" src="js\jquery.validate.js"></script> 
<script> 
$(document).ready(function(){ 
$("#submission").validate({ 
    rules: { 
     appSize: { 
     required:true, 
     max:12 }, 
     appName: { 
     required:true, 
     rangelength:[4,9] }, 
     appPrice: { 
     required:true, 
     min:.99, 
     max:3.99 }, 
     email: { 
     required:true, 
     email:true } 
    }, 
    messages: { 
     appSize: { 
     required: "App Size is a required field"}, 
     appName: { 
     required: "App Name is a required field", 
     rangelength: "The name must be between 4 and 9 characters" }, 
     appPrice: { 
     required: "App Price is a required field", 
     min: "Price must be .99 or greater", 
     max: "Price must be less than 3.99" }, 
     email: { 
     required: "email is a required field", 
     email: "You must enter a valid email address" } 

    }, 
    errorElement: "div" 


}); 

}); 
</script> 
    </head> 
     <body> 
     <form id="submission" method="post" action="#"> 
      <h1>Apple iPhone App Contest Submission Page</h1> 
      <div id="theForm"> 
       <div> 
       <label for="appSize">What is the file size in KB?</label> 
       <input name="appSize" type="text" id="fileSize" class="required"></input> 
       </div> 
       <br /> 
       <div> 
       <label for="appName">What is the App Name?</label> 
       <input name="appName" type="text" id="appName" class="required"></input> 
      </div> 
      <br /> 
      <div> 
       <label for="appPrice">What is the App Price? $</label> 
       <input name="appPrice" type="text" id="appPrice" class="required"></input> 
      </div> 
      <br /> 
      <div> 
        <label for="email">Submitters Email Address</label> 
        <input name="email" type="text" id="email" class="required"></input> 
      </div> 
      <br /> 
      <input type="submit" class="btn" value="Submit"/> 
     </div> 
    </form> 
    </body> 
</html> 
0
success: submit = true 

あなたがつもりか仕事に行くされていません。ここでは、コードです。

そのプロパティに関数を割り当て、そこで実行する必要がある操作を行います。

+0

私は完全にそれを行う方法がわかりません...これは私がjquery検証プラグインを使用した初めてです。 –

0

あなたのコードはちょっと混乱しているようです... 送信ボタンを隠すと、どのようにフォームを送信できると思いますか? 私はあなたのフォーム入力にバリデーションを呼び出すためにいくつかの "onchange"イベントをバインドすることができると思います。しかし、これは、あなたが入力中に別の入力に渡しても検証が実行されることを意味します。

関連する問題