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

134
Views
How to validate form Dynamically added?

I have a form which adds a line dynamically when click on add form.

<form class="address">
  <input type="text" class="add_name">
  <input type="test" class="add_zip">
</form>

When Clicked on lets say a button add address:

<form class="address">
  <input type="text" class="add_name">
  <input type="test" class="add_zip">
    //added line when clicked on btn
  <input type="text" class="add_name">
  <input type="test" class="add_zip">
</form>

I used following code

 $('.address').each(function(){
    var address_form = $($this);
    if(address_form.find('.add_name').val() == ''){
       //dosomething
     }else{
        console.log(address_form.find('.add_name').val());
     }
 });

lets say if I put both address only first address is shown and second one undefined.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You could try the following:

$('button').on("click",function(ev){
  const inps=$(".address input").slice(0,2).clone().val("");
  $(".address").append(inps).append("<br>")
 });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form class="address"><input type="text" class="add_name" name="name[]"
  placeholder="Enter your name"><input type="test" class="add_zip" name="zip[]" placeholder="and zip code"><br></form>
<button>add fields</button>

I added a name attribute to your input fields. By doing this the data can be collected on the backend in suitable array structures for name and zip.

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!