Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

251
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda