Forums

Adapt "How can I have a button to add more form inputs?"

peterswa62 27 Feb, 2013
Hi. I've adapted your example to have a button to add more inputs on this link:-

http://www.chronoengine.com/faqs/2700-how-can-i-have-a-button-to-add-more-form-inputs.html

I've got it to load saved inputs from the database but am stuck on how to adapt the JavaScript code to show these inputs and not just one empty one to put a new one in.

I think where you have this code:-
// display the next row and hide the last 'Add one' button
function addOne(id) {
  $('addone_'+id).setStyle('display', 'none');
  $('recipient_'+id).setStyle('display', 'block');
};

If you have say 5 inputs you would need to somehow call this 6 times to show all inputs and an empty one at the bottom to put another in.
GreyHead 01 Mar, 2013
Hi peterswa62,

I think I would show the existing values by editing the PHP in my form to show the necessary number of rows before the form loads, then set a counter variable for the JavaScript to read to know which is the next one to add.

Bob
This topic is locked and no more replies can be posted.