2017-01-01 3 views
-2

ユーザ名、メールアドレス、パスワードのいずれかが空の場合にフォームの送信ボタンを無効にしようとしていて、ユーザがすべてを入力して送信ボタンを有効にしています。次のコードは送信ボタンを無効にしません。次のjqueryコードが送信ボタンを無効にしないのはなぜですか?

おかげ

HTMLコード:

<form id="new_user_form"> 
             {% csrf_token %} 
            <div class="modal-content" data-method="post" id="modalform" > 
              <div class="modal-header"> 
               <button type="button" class="close" data-dismiss="modal">&times;</button> 
               <h4 class="modal-title">Sign Up</h4> 
              </div> 
             <div onload="validateForm();" class="modal-body"> 
              <div class="form-group"> 
               <label for="usr">Username:</label> 
               <input type="text" name="username" class="form-control input-sm" id="username"> 
               <label for="eml">Email:</label> 
               <input type="email" name="emil" class="form-control input-sm" id="emailid"> 
               <label for="passwordd">Password:</label> 
               <input onchange="checkPasswordMatch();" type="password" name="password" class="form-control input-sm" id="password"> 
               <label for="passwordd">Retype Password:</label> 
               <input type="password" name="retrypassword" class="form-control input-sm" id="retrypassword"> 
               <br/><div style="color:blue;" id="doesPasswordMatch"> </div> 
               <span class="help-block">Ensure, You Choose Correct Profession...</span> 

             <label for="inputfile">Upload Profile Picture</label> 
             <input type="file" id="inputfile"> 
             <p class="help-block">The Profile Picture help people to identify you.</p> 
              </div role="Form group"> 
              </div role="modal-dialog"> 
         <!--Closing Of Sign Up Modal Page --> 
               <div class="modal-footer"> 
                   <button type="submit" class="btn btn-default" id="submit" onclose="showSuccessMessage();">Submit</button> 
                   <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
               </div role="modal-footer"> 
            </div role="modal content"> 

のjQueryコード:

<script type="text/javascript"> 
    function checkPasswordMatch() { 
     if ($('#password').val() == $('#retrypassword').val()) 
      $('#doesPasswordMatch').html("<h4> Match </h4>").css('color', 'rgb(34,139,34)'); 
     else 
      $('#doesPasswordMatch').html("<h4> Does not match </h4>").css('color', 'rgb(128,0,0)'); 

    } 
    $(document).ready(function() { 
     $('#submit').attr('disable', true); 
     $('#retrypassword').keyup(checkPasswordMatch); 
     if ($('#username').val() == '' || $('#email').val() == '' || $('#password').val() == '') 
      $('#submit').attr('disable', false); 
    }); 
</script> 
+0

'attr'の代わりに' prop'を使用します – Musa

+0

@Musa:jQueryがあなたのために修正するので、 'attr'が動作しますが、まあまあです。 –

+0

これは無効になっていません。 – sheavens

答えて

3

プロパティがdisabled(端でd有する)、ないdisableあります。そしてattrは、歴史的な理由のためにあなたのためにこれを処理しますが、それを設定する正しい方法はprop経由で:

$("#submit").prop("disabled", true); 
// ----------^^^^---------^ 
+0

それはまだ動作しません、これは何のためにdownvotingですか? – Ahtisham

+0

@Ahtisham:まだ動作しない場合、コードに*別の*問題があります。これは飛び出した明白なものです。デバッガを使用してコードをステップ実行し、変数などを検査します。 –

1

それは、これは動作するはずdisabledとNOT disable

次のようになります。

$('#submit').attr('disabled',true); 

または

$('#submit').attr("disabled","disabled"); 
+0

これはまだ動作しません。これは何のためにdownvotingですか? – Ahtisham

+0

私はあなたの質問をd​​ownvoteしませんでした..他人が持っている可能性があります。 –

+0

okay brodaあなたのために私の投票に行く:)しかし、それはまだ動作しません:( – Ahtisham

関連する問題