I have simple form with 2 textfield Name and Phone and can add new field when click Add new button. You can refer here jsfiddle .
My problem is how to add new textfield without press Add New button? When user fill up Text Input name and Text Input Phone new row <tr class="person"> will automatically added.
My second problem is I’m not sure how to write code for delete.
UPDATE : I also want to set maximum clone, can this be done?
If by “fill up” you mean “when the user enters as many characters as the Phone field allows” then you can add a
maxlength="10"attribute to the input (setting the value as appropriate):…and add a handler to the
keyupevent that checks whether the current value has reached themaxlength:Note that you probably only want to do this test if the user is typing in the last row, hence the first part of the
iftest above.Also you probably want the newly cloned fields to be blank, so you can do this within your add function:
To set a maximum number of rows you can put a test in your add function:
Note also that you don’t need to give those inputs an
idattribute, but if you do you shouldn’t copy it when you clone becauseidshould be unique.For a delete function, add a delete button to each row:
…and then:
Demo: http://jsfiddle.net/3J65U/15/