I know this has been asked many times but my code not working after looking at similar questions.
Form
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
<div class="form-group">
<input type="file" name="file" id="fileToUpload" required="">
</div>
<input type="submit" value="Upload Image" id="submit" name="submit" class="btn btn-info">
<img src="authors/loading.gif" id="loading" style="max-height: 30px; width: auto; display: none;">
</form>
Script
<script type="text/javascript">
$('#form1').on('submit', function(e) {
e.preventDefault();
$('#submit').hide();
$('#loading').show();
this.submit();
});
</script>
I am trying to hide submit button on click and then show a loading gif but it is directly submitting.
jQuery library all included and no error is showing in the console.
this.submit()?this.submit()it is directly submittinge.preventDefault()should work. You must have something wrong elsewhere making you think that the form is submitted anyway.