SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    dynamic form fields

    Now i have a question. I wanto make a custom slideshow generator, and that users can add their image links. Now the problem is i don't wan't to limit my users to let's say 5 iage links, i would like to make somthing that will alow them to add as much input fields as they won't and then when they submit that they get the proper slideshow code with as those fields. so if anybody now's how to do this i would me more thank thankfull. I think i saw somthing slike this somewhere but i cant remember. Thank you

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Heres an example
    Code:
    <html>
    <head>
    <script type="text/javascript">
    function addNewLink() {
    	var frm = document.getElementById("theForm");	
    	var copyMe = frm.getElementsByTagName("div")[0].cloneNode(true);
    	copyMe.getElementsByTagName("input")[0].value = "";
    	frm.appendChild(copyMe);
    	copyMe.getElementsByTagName("input")[0].focus();
    }
    </script>
    </head>
    <body>
    <form id="theForm">
    <div>
    Image link: <input type="text" name="imageLink" />
    </div>
    </form>
    <button onclick="addNewLink();">Add image link</button>
    </body>
    </html>

  3. #3
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you very much, but now i am having trouble with submiting those form fields. When i press do submit button let's say it should transfer you to a page like makeslideshoe.php. How do i read the names for the forms. Becuse i need to have variables on that form fields so when somebody presses submit on the next page he usese those inputed variables. thank you very much

  4. #4
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    182
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could you do this:

    Image link: <input type="text" name="imageLink[]" />

    Then PHP has an array of all the imageLinks?

  5. #5
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah do that, I forgot about php needing [] to access post elements as an array.


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
  •