How to Copy Form Values Into Another Form Using Jquery

Recently I have a requirement to have two form on a single page.

Why? It's because I have a search form that query records from the database with the aid of ajax. Then another form to generate a report based from the filters specified in the first form.

So when the submit button from the search form is pressed, it populates the fields on the second form with values from the first form. And here's how I did it in jquery:

$(':input[name]', "#searchForm").each(function () {
  if ($(this).attr('name') != 'SubmitButton') {
  $('[name=' + $(this).attr('name') + ']', "#generateReportForm").val($(this).val());
  }
})   

0 Comments

Post a Comment

Post a Comment (0)

Previous Post Next Post
NERV Open Source

Building production Spring Boot systems?

Explore NERV — open-source Java libraries for audit trails, persistence, exception handling, and reliable event-driven architecture.

Explore NERV on GitHub →