Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

161
Views
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>

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!