Results 1 to 2 of 2

Thread: Interact With a Form

  1. #1
    Join Date
    Mar 2010
    Location
    Canada
    Posts
    32
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Interact With a Form

    When I click on an "Add" button, it would create a new form with the "First Name", "Last Name" field and 2 textboxes, just like the original.
    So if I click on the "Add" button 5 times, it would create 5 new forms for me. Same idea applies for the "Delete" button.

    Here's my code:
    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset=utf-8 />
    <title>JS Bin</title>
    </head>
    <body>
       <FORM NAME="myForm">
       First Name: <input type="text" name="1stName" ><br />
       Last Name: <input type="text" name="lastName" ><br /><br />
       <input id="bu_add" type="button" value="Add" >
       <input id="bu_delete" type="button" value="Delete">
       </FORM>
    </body>
    </html>

    If you can help me out, I would greatly appreciated. Or if you know what this is call, I can just look it up.

    tks

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Do you want the add and delete buttons duplicated as well or not?

    Anyways, in about simplest terms (assuming we're not duplicating the buttons):

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset=utf-8 />
    <title>JS Bin</title>
    <script type="text/javascript">
    function addform(){
    	var newform = document.forms[0].cloneNode(true);
    	newform.name = 'myForm' + document.forms.length;
    	newform.removeChild(newform.elements[2]);
    	newform.removeChild(newform.elements[2]);
    	document.body.appendChild(newform);
    }
    function removeform(){
    	var formnumber = document.forms.length - 1;
    	if(formnumber){
    		document.body.removeChild(document.forms[formnumber]);
    	}
    }
    </script>
    </head>
    <body>
       <FORM NAME="myForm">
       First Name: <input type="text" name="1stName" ><br />
       Last Name: <input type="text" name="lastName" ><br /><br />
       <input id="bu_add" type="button" value="Add" onclick="addform();">
       <input id="bu_delete" type="button" value="Delete" onclick="removeform();">
       </FORM><br />
    </body>
    </html>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. Interact With Facebook & Twitter
    By locbtran in forum PHP
    Replies: 2
    Last Post: 10-06-2012, 06:42 PM
  2. Replies: 0
    Last Post: 12-13-2010, 09:40 PM
  3. Replies: 0
    Last Post: 05-24-2008, 09:53 PM
  4. Recall Form Values script 1 - problem after submitting form
    By FirkinB in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 05-01-2007, 08:50 PM
  5. How to interact pages!
    By Mob1us in forum JavaScript
    Replies: 2
    Last Post: 08-25-2006, 08:14 PM

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
  •