preventdefault - jQuery prevent default not working on form submit -


i trying test getting image size form, , instead of submitting form, want preventdefault, , show alert instead.

here script:

<script type="text/javascript"> function update1() {     event.preventdefault();     var fileupload = document.getelementbyid("uploadfile");     if (typeof (fileupload.files) != "undefined") {         var size = parsefloat(fileupload.files[0].size / 1024).tofixed(2);         alert(size + " kb.");     } else {         alert("this browser not support html5.");     } } </script> 

and here html:

<form action="" method="post" enctype="multipart/form-data">               <div class="owner-panel owner-panel-space-4">     <div class="owner-panel-body">         <div class="row">             <div class="col-md-4">                 <h4>image</h4>             </div>             <div class="col-md-8">                 <div class="input-group">                     <span class="input-group-btn">                         <span class="btn btn-danger btn-file">                             browse… <input id ="uploadfile" type="file" name="image" multiple="">                         </span>                      </span>                     <input type="text" class="form-control filename" readonly="">                 </div>             </div>         </div>         <div class="row">             <div class="col-md-4">                 <h4>caption</h4>             </div>             <div class="col-md-8">                 <input class="form-control image-caption-counted" type="text" name="imagecaption" id="imagecaption" />                 <h6 class="pull-right" id="image-caption-counter">40 characters remaining</h6>             </div>         </div>     </div>     <div class="owner-panel-footer">          <button class="btn-u" type="submit" name="action" value="update1">upload</button>              </div>      </div>            </form>  

is there reason why event.preventdefault(); isn't working here? in correct position?

you need pass event in function args:

update1(event){    //..... } 

note:

i didn't see event handler calling update1() function.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -