I have a form with mandatory inputs and added a onClick event listener on the submit button to display a loading git when the program is charging. The problem is that the onClick function is triggered every time the button is clicked and I want it to be only if the form is complete and sent.
How can I put a condition in my jQuery function for that ?
Here is the HTML and JS:
<div id="loading"></div>
<div id="content">
<form enctype=multipart/form-data action={{url_for('upload_file')}} method="POST" enctype="multipart/form-data">
<h3>MGR</h3>
<label for="file-input" class="col-sm-4 col-form-label">The music (.wav or .mp3):</label>
<input type="file" id="file-input" name="file" class="form-control w-100" required="true"/><br>
<br>
<div class="form-group">
<h4>Select a model</h4>
<input type="radio" id="logreg" name="model" value="logreg" required>
<label for="logreg">Logistic regression</label><br>
<input type="radio" id="knn" name="model" value="knn">
<label for="knn">K-nearest neighbors</label><br>
<input type="radio" id="randomforest" name="model" value="randomforest">
<label for="randomforest">Random forest</label><br>
<input type="radio" id="svm" name="model" value="svm">
<label for="svm">Kernel SVM</label><br>
</div>
<input type="submit" value="Submit" onclick="loading();" class="btn btn-primary"></form>
</div>
<script type="text/javascript">
function loading(){
$("#loading").show();
$("#content").hide();
}
</script>