SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2005
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Add and delete form fields BUT a textarea or a section of input fields

    Hi all,

    I have been looking for the past 2 days for a script that I can add and delete table rows.

    I have found a lot but so far all of them add an input field but I desperatly need a textarea or ideally a section of input fields.

    I have tried to change the code from input to text area but none of them worked.

    Have you come across to a similar script.

    I would appreciate any contributions.

    What I am trying to do is a page where the user will add their employees details so we can order business cards for them. So I have fileds such as, Name, Tel Num, Email, Cell etc.

    That's why I need more than one fields to repeated.


  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I do it like this, it's easy and quick:
    Code:
    <html>
    <head>
    <title>Adding new elements to a form</title>
    <script type="text/javascript">
    function addNewElements() {
    	var hiddenDiv = document.getElementById("hiddenElements");
    	var newElements = hiddenDiv.cloneNode(true);
    	newElements.style.display = "block";
    	document.getElementById("someElements").appendChild(newElements);
    }
    </script>
    </head>
    <body>
    <form>
    <button onclick="addNewElements();">Click to add elements</button>
    <div id="someElements"></div>
    <div id="hiddenElements" style="display:none;">
    Name:<textarea name="empName">enter name here</textarea>
    Phone:<input type="text" name="empPhone" />
    Email:<input type="text" name="empEmail" />
    </div>
    </form>
    </body>
    </html>

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2005
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you so much...!!!...

    You made it look so simple.

    It was impossible to find something like that, mamy thanks again!!!

  4. #4
    SitePoint Enthusiast
    Join Date
    May 2005
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just to let you know that I've just tested it in firefox (1.5) and it doesn't work. It appears and disappears instantly like it's flickering.

    works smooth in ie.

  5. #5
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Strange. It needs to have false returned. This works:

    <button onclick="addNewElements();return false;">Click to add elements</button>


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
  •