简体   繁体   中英

For, enter to focus next element disables js validation

Please check below js fiddle:

https://jsfiddle.net/Lfz567tw/

I have created a form in which when I enter, it selects next input and at last, submits the form.

But this function disables my validation function and on submitting the form, function validate() is not working.

Is there any way I can fire function validate() also when submitting the form?

There is simple example to show you how you can check or call your validate function before form submittion

e.preventDefault : Used for prevent default functionallity

 $(function() { $("#entertonext").submit(function(e) { e.preventDefault(); // validate code (calling function) validate(); }); }); function validate() { alert('Validating'); } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <div class="card-block" id="entertonext"> <form name="bank" action="#" method="post"> <div class="form-group row" > <label for="default-input" class="col-sm-2 form-control-label">Account No.</label> <div class="col-sm-10"> <input type="text" class="form-control entertonext" name="acc_no" id="acc_no" placeholder="Account No." tabindex="1" onblur="validate(this,event)"> <span id="msg8"></span> </div> </div> <div class="form-group row"> <label for="default-input-rounded" class="col-sm-2 form-control-label">Branch Name</label> <div class="col-sm-10"> <div class="input-group icon icon-lg icon-color-primary"> <input type="text" class="form-control entertonext" name="b_name" id="b_name" placeholder="Branch Name" tabindex="2"> </div> <span id="msg2"></span> </div> </div> <div class="form-group row" id="drawn" > <label for="default-input" class="col-sm-2 form-control-label">IFSC Code</label> <div class="col-sm-10"> <input type="text" class="form-control entertonext" name="ifsc_code" id="ifsc_code" placeholder="IFSC Code" tabindex="3"> <span id="msg5"></span> </div> </div> <div class="form-group row" id="deposited"> <label for="default-input" class="col-sm-2 form-control-label">Address</label> <div class="col-sm-10"> <textarea class="form-control entertonext" name="address" id="address" placeholder="Address" tabindex="4"></textarea> <span id="msg6"></span> </div> </div> <div class="form-group row" id="deposited"> <label for="default-input" class="col-sm-2 form-control-label">Bank Balance</label> <div class="col-sm-10"> <input type="text" class="form-control entertonext" name="balance" id="balance" placeholder="Bank Balance" tabindex="5"> <span id="msg6"></span> </div> </div> <div class="form-group row"> <div class="col-sm-10"> <button type="submit" class="btn btn-primary entertonext" tabindex="6">Submit</button> </div> </div> </form> </div> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM