'Javascript : My function sweetalert is not working on click
I am a beginner in JavaScript. I want to add a sweetalert to my webpage when the user click on the button to upload a files. If he has selected nothing, so the list of files is empty it should appear an error. If he has selected something, it should be true.
When I run it, nothing appears when I click on the button upload. What should I change that it works ?
validatefile = function() {
var input = document.getElementById('id_Filename').files.length;
console.log(input)
if (input == 0){
swal("Opsss !", "You have not select files", "error")
return false;
}
else{
return true;
}
}
$("#submitupload").bind("click", validatefile);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<div class="upload-in">
<h2>Upload</h2>
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="csrfmiddlewaretoken" value="AgRDs73CilF7muSe47HHhvm0Hoszk9xSFDUW2QNCeOFwSU4PYr5ggebYtfL8vdvI">
<p>
<label for="id_Filename">Filename:</label>
<input type="file" name="Filename" multiple="" onchange="javascript:updateList()" maxlength="255" id="id_Filename">
</p>
<button type="submit" id="submitupload">Upload</button>
</form>
<div class="fileselect">
<p>Selected files :</p>
<div id="fileselect"><ul></ul></div>
</div>
</div>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
