hi,
I have an HTML form setup. It has several input text fields to enter the data. I also want the user to add more text fields dynamically if he wishes to enter more data. If I do it directly though PHP using loops, I loose the data previously entered in the fields.
I was wondering about implementing Ajax to solve this probelm to generate multiple text fields. I am new to using Ajax technique, and I do not have solid JavaScript background, and I am kind of strugling.
Thanks very much! Any help would be greatly appreciated!
You don’t need AJAX for that.
Here is an example of how you can add new fields using Javascript.
<form action="somewhere.php">
<div id="fields">
<input type="text" name="test[]">
<input type="text" name="test[]">
</div>
<div><input type="button" id="addFieldButton" value="Add Field"></div>
</form>
document.getElementById('addFieldButton').onclick = function() {
fDiv = document.getElementById('fields');
field = document.createElement('input');
field.setAttribute('type', 'text');
field.setAttribute('name', 'test[]');
fDiv.appendChild(field);
}