954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

create text field using ajax

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!

computerages
Light Poster
27 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
 

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

ShawnCplus
Code Monkey
Team Colleague
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268
 

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.

langsor
Posting Whiz
390 posts since Aug 2008
Reputation Points: 30
Solved Threads: 36
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You