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

250
Vistas
How to get HTML cloned form values

I'm trying to get the values from my form when the user clones the row. When I clone the rows are the id still the same? If so how do I make the new rows to have a unique id?

jQuery(function($) {
  var $button = $('#add-row'),
    $row = $('.period-row').clone();

  $button.click(function() {
    $row.clone().insertBefore($button);
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<h3 class="heading">Please select appointment period</h3>
<div class="form-wrapper">
  <form action="#" id="date-form" name="date-form" method="POST">
    <div class="period-row">
      <label for="start">From:</label>
      <input type="datetime-local" name="start[]" id="start">
      <label for="end">To:</label>
      <input type="datetime-local" name="end[]" id="end">
    </div>
    <input type="button" id="add-row" name="add-row" value="add period" />
    <button type="submit">submit</button>
  </form>
</div>

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

0

I don't understand what exactly you want and to do it on the proper way you have to use class on the input and not id because the id is unique. But I hope this code will help you.

jQuery(function($) {
  var $button = $('#add-row'),
  $row = $('.period-row').clone();

  $button.click(function() {
    let from = $('#start').val();
    let to = $('#end').val();
    $row.clone().insertBefore($button).addClass('active');
    $('.period-row.active').find("#start").val(from);
    $('.period-row.active').find("#end").val(from);
    $('.period-row').removeClass('active');
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<h3 class="heading">Please select appointment period</h3>
<div class="form-wrapper">
  <form action="#" id="date-form" name="date-form" method="POST">
    <div class="period-row">
      <label for="start">From:</label>
      <input type="datetime-local" name="start[]" id="start">
      <label for="end">To:</label>
      <input type="datetime-local" name="end[]" id="end">
    </div>
    <input type="button" id="add-row" name="add-row" value="add period" />
    <button type="submit">submit</button>
  </form>
</div>

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