javascript - jQuery, submit is not cancelling on form -


i have form trying use js cancel, can submit using ajax.

however started , made form , tested see if submission cancelled/return's false discovered did not. checked other threads/posts made none helped me. form bellow, followed .js file. console in chrome has not given me errors either.

edit: forgot mention alert in .js file not coming either.

<form method="post" class="form-horizontal form-bordered" id="user-data-form">     <div class="form-group">         <label class="col-md-3 control-label" for="oldpassword">old password</label>         <div class="col-md-6">             <input type="password" id="oldpassword" name="oldpassword" class="form-control" placeholder="old password">         </div>     </div>     <div class="form-group form-actions">         <div class="col-md-9 col-md-offset-3">             <!-- submit element -->             <input type="submit" class="btn btn-effect-ripple btn-primary" value="update">             <!-- end submit element -->         </div>     </div> </form> 

and js file,

$( '#user-data-form' ).submit( function(event) {         alert( "handler .submit() called." );         event.preventdefault();         return false;     }); 

i suggest try making event.preventdefault(); first thing runs alert maybe allowing normal button pressing function of html form run while alert sits on screen

$( '#user-data-form' ).submit( function(event) {     event.preventdefault();     alert( "handler .submit() called." );     return false; }); 

as per comment:

add javascript before

<script src="js/test.js"></script> </body> </html> 

otherwise not part of dom , wont run

as per second comment

try putting code inside .ready this. ensures document built before attempting attach .submit handler. , stops attempting add handler before there object attach in dom.

$( document ).ready(function() {     $( '#user-data-form' ).submit( function(event) {         event.preventdefault();         alert( "handler .submit() called." );         return false;     }); }); 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -