0

I am doing jQuery form validations for blank fields. If any field is blank, i am able to disabling the submit button.

html

    <div class="row popular">
       <div data-val="AXIS"><img src="images/axisbank.gif">
        </div>
       <div data-val="HDFC"><img src="images/hdfcbank.gif">
       </div>
    </div>

   <input name="" type="text" id="banknametxt" placeholder="Select Bank Name">
   <div class="row center bankbt">
      <a href="javascript:" class="bt btblue netBankPay disableClick" id="submitBtn">
      <img src="images/icon_pay.png"> Pay</a>
   </div>

If i click on the radio button, i am able to setting the value in the textbox But the button is still disable.(i.e, need to enable the button)

jquery

  $(function() {
    activatePayButton('submitBtn'); 
    $(".popular div").click(function() {
         var nameAttr = $(this).attr('data-val');
          $("#banknametxt").val(nameAttr);
      });

    function activatePayButton(formId){
        $form = $('#'+formId);     
        $form.find(':input').on('change keyup blur', function(event) {                                     
        var disable = false;   
        $form.find("input[type!='hidden']").each(function(i, el) {
           if ($.trim(el.value) === '') {
              disable = true; 
           }
        });
        if(disable == true){    
          $form.find('#submitBtn').addClass('disableClick');
         } else{
          $form.find('#submitBtn').removeClass('disableClick');
         }
      });
    }
    });
3
  • 1
    $form = $('#'+formId); point to the button, so, $form.find("input[type!='hidden']") return null jquery collection. Commented Sep 9, 2015 at 10:09
  • you need to call the change event of the text box manually $("#banknametxt").change() Commented Sep 9, 2015 at 10:10
  • thanks KishoreSahas..it's working fine. Commented Sep 9, 2015 at 10:31

2 Answers 2

1

After changing value with $("#banknametxt").val(nameAttr); will not invoke $form.find(':input').on('change keyup blur' event.

If you want to do so after changing value from jquery use this

$("#banknametxt").val(nameAttr);
$("#banknametxt").trigger('change');//manually triggering event
Sign up to request clarification or add additional context in comments.

Comments

0

Add click binding to the button with disableClick class.

$(document).on('click','a.disableClick',function(event){
    event.preventDefault();
    event.stopImmediatePropagation();
}  

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.