Results 1 to 4 of 4

Thread: adding dynamic text fields

  1. #1
    Join Date
    Jul 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default adding dynamic text fields

    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

    shiva

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    If you create fields with the same name that ends with [] (e.g.
    Code:
    <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:
    Code:
    for($i = 0; $i < count($_GET['myField']); ++$i)
      print $_GET['myField'][$i] . "\n";
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Jul 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •