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

249
Views
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 answers
Answer question

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 Report
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!