View Full Version : adding dynamic text fields

07-07-2007, 11:57 AM
hi all

This is Shiva ,I am new to dynamicdrive forums and php also,

In my work I want to create dynamic text fields,And pass these values to the database.
I am having three text fields by name Text1,Text2,Text3 in a single row .

In the same as above row ,i have to create dynamic rows,and pass these dynamic row values to the database along with the static row values.

The main problem exist here only.
If I use java script i cant able to pass the dynamic values to the database,because in the Js i have created the text fields with the same name.

Some body told that It may possible in php also with help of arrays( without using javascript)

So Any experienced coders help me plz.:(
Thanks in Advance


07-07-2007, 12:01 PM
If you create fields with the same name that ends with [] (e.g.
<input type="text" name="myField[]">
<input type="text" name="myField[]">
<input type="text" name="myField[]">
<input type="text" name="myField[]">) then you can access it in PHP as an array:
for($i = 0; $i < count($_GET['myField']); ++$i)
print $_GET['myField'][$i] . "\n";

07-07-2007, 12:07 PM
if the rows are in limited then there is no problem .But the requirement is dynamic rows,that means i may add n number of rows .

One more thing Twey,beside the static row i have to keep button namely ADD ANOTHER ROW ,like this ,so how to keep this .

plz help Me.
Fighting with this since last night.

07-07-2007, 02:37 PM
<input type="button" onclick="this.form.appendChild((function(v) { (v = document.createElement('input')).type = 'text'; v.name = 'myField[]'; return v; })(0));">Beware, though, that this should only be a convenience method, since it's possible the client won't have Javascript enabled.