I have a form and I want to be able to add additional input fields when a button is clicked. The name of the input field will stay the same because the name creates an array for my PHP code. The following script works, however when you add another field if you have text entered, it adds the field but clears out all text in the added fields.
1. How do I keep those values when you click the add button?
Next I want to be able delete if the user clicks the add button too many times. I know I need to pass the id value to a delete function but…
2. How should the delete function look to achieve this.
Here is the code that works (to add a field) and posts to my database perfectly.
[CODE]
function addColorInput() {
var id=0;
for (id=0; id < 100; id++) {
var idName = “id='”;
var form = “<input type=’text’ name=’color[]’ id='”+id;
var div = document.getElementById(“color”);
}
div.innerHTML += “<div>Next Color: “+form+”‘<br /><br /></div>”;
}
Any advice would be appreciated.