Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

169
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda