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

124
Vistas
Enable capture attribute for file input depending on label clicked

I have the following form with two labels:

                <form method="POST" action='/process' enctype="multipart/form-data">
                    <div>
                        <label for="file" class="upload-button"><i class="far fa-file-image"></i></label>
                        <label for="file" class="upload-button"><i class="fas fa-angry"></i></label>
                        <input type="file" id="file" name="file" accept=".jpg, .jpeg, .png" style="display: none; visibility: none;" onchange="$('form').submit();">
                    </div>
                </form> 

I would like the input to remain as it is currently written if the first label is clicked, but for a 'capture="user"' attribute to be added if the second label is clicked. Is there an easy way of achieving this?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

First, give the second label a unique class:

<label for="file" class="upload-button second"><i class="fas fa-angry"></i></label>

Then, select it, and add to it a click event listener that gives the <input /> tag a "capture"="user" attribute using attr() method:

$(".second").click(function() {
  $("input").attr("capture", "user");
});

Running sample: inspect the input tag to see the change

$(".second").click(function() {
  $("input").attr("capture", "user");
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta2/css/all.min.css" rel="stylesheet" />
<form method="POST" action='/process' enctype="multipart/form-data">
  <div>
    <label for="file" class="upload-button"><i class="far fa-file-image"></i></label>
    <label for="file" class="upload-button second"><i class="fas fa-angry"></i></label>
    <input type="file" id="file" name="file" accept=".jpg, .jpeg, .png" onchange="$('form').submit();">
  </div>
</form>

about 4 years ago · Juan Pablo Isaza Denunciar
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