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!

Recommended Answers

All 2 Replies

People are throwing around the word AJAX as if it is synonymous with DHTML.

var container = document.getElementById('the_form_container');
var newfield = document.createElement('input');
newfield.type = 'text';
newfield.id = someCounter+'_suffix';
container.appendChild(newfield);

^ Not AJAX

Member Avatar for langsor

You can use DHTML as mentioned above ... no problem. Or if you want to stick to the ol' familiar PHP looping you can do something like this to keep the value of your form field on page reload ...

<input type="text" name="test" value="<? print $_GET['test'] ?>" />

If page reload is what you mean by loops.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.