in Education by
I'm builtin an web resume-generator to learn how to develop for web. I've made a HTML form which the user can add more fields to add more information's about him. Example: he has more than one professional experience, but the form starts with a single prof-exp field to fill. So he clicks in a "add new exp" button and the JS creates a new field for it. I used the clone() method from jQuery to do this, but this gives me with the problems I've listed bellow. Also, here's the code I've made: var index = 0; $(document).ready(() => { $("#add-exp").click(() => { $("#professional").clone().attr("id", "professional" + index++). appendTo("#professional-info").find("select, input, textarea").val(""); }) }) <!DOCTYPE html>
professional experience



Run code snippetExpand snippet The problems are: Only the divs have dynamic ID's, which causes me the following two other problems; I don't know how to implement the remove button logic, since I cannot make difference between the 1st button and the other ones from other divs; Since the labels use their correspondent input ID to make reference, when the user clicks it, they point to the first field inputs; I hope you guys could understand my problem and help me with it. Also, sorry for my english - i'm learning too. Thank you all! JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
As suggested, Vue.js is cool, but jQuery has some forgotten powers too. And, since you create elements dynamically, don't use IDs. And submit to the backend your experiences as arrays []: i.e: name="carrer[]", name="company[]" etc. Than on the backend loop those data arrays to retrieve all the user experiences. const new_exp = () => $('
', { 'class': 'professional-exp', html: `



`, append: $('
Professional experience
Run code snippetExpand snippet Above we're defining the Remove's button action right within the template, but if you want you can also hardcode the button into the template and create a dynamic click handler (using jQuery's .on()) like: const exp_new = () => $('
', { 'class': 'professional-exp', html: `



`, appendTo: '#professional', }); jQuery($ => { // DOM ready and $ alias in scope exp_new(); // On init (Create first exp) $("#exp_new").on('click', exp_new); // and on click. $('#main').on('click', '.exp_delete', ev => $(ev.target).closest('.professional-exp').remove()); }); .professional-exp { padding: 10px; margin-bottom: 10px; background: #eee; }
Professional experience
Run code snippetExpand snippet

Related questions

0 votes
    I'm builtin an web resume-generator to learn how to develop for web. I've made a HTML form which ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    How can I replace a specific text with HTML objects? example: var text = "some text to replace ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 25, 2022 in Education by JackTerrance
0 votes
    How can I replace a specific text with HTML objects? example: var text = "some text to replace ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 24, 2022 in Education by JackTerrance
0 votes
    I have dropdown in my form which has a CSS style defined on pageload and is hidden and the code ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 3, 2022 in Education by JackTerrance
0 votes
    Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 10, 2022 in Education by JackTerrance
0 votes
    Please take a look at the following code... $("#page_info_select_box").live("keypress",function(){ var sele = "domain"; var inp ... :sele},function(data){ //alert(data); for (i=0;i...
asked Feb 21, 2022 in Education by JackTerrance
0 votes
    Is there an 'official' way to get all input elements of a form including those outside of the form ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I have a background image on top of which there is some text. It is very hard to read the text ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 26, 2022 in Education by JackTerrance
0 votes
    I want to calculate browser height without considering browser address bar and bottom navigation bar height. The ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I want to calculate browser height without considering browser address bar and bottom navigation bar height. The ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    I am currently trying to create an autocomplete with a source that is stored in a javascript variable but ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 18, 2022 in Education by JackTerrance
0 votes
    I am building a basic RSS reader app that, which the 'story' is clicked, the information for it is displayed in a modal ... .log('Does Not Work!'); Or another way: - overscroll...
asked Jul 30, 2022 in Education by JackTerrance
...