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

279
Views
In Django, how to modify field names in dynamic forms using Java Script

I created a form. Using jQuery got first para of form. Using add function I am adding it again. With this I am getting same names for all the new fields. I am not able to retrieve its values in views.py.

Is there any way to change form field names in js? or any other solution to it?

JS Function:

$(".add").click(function() {
    $("form > p:first-of-type").clone(true).insertBefore("form > p:last-child");
    return false;
});

$(".remove").click(function() {
    $(this).parent().remove();
});

With this JS I am cloning this lines,

<input type="text" name="med" maxlength="100" required id="id_medicine">

While sending it back, I need to change name of the input field(med to med1). So, that I can fetch all values in views.py

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

0

You are just cloning what is there on first para of form, use input name as array and use different empty inputs with same array name when adding of next para. for eg-

<div class="row">
 <input type="text" name="arr1[]" >
 <input type="text" name="arr2[]" > 
</div>
<button id="add"> Add</button>
    
  $('#add').click(function(){
    
      $('.row').append('<input type="text" name="arr1[]" ><input type="text" name="arr2[]">');
    })
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!