SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Multiply Fields

  1. #1
    SitePoint Addict
    Join Date
    Nov 2002
    Location
    Maryland
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Multiply Fields

    Hello,
    The following code creates input boxes dynamically when you click on the button.
    http://clients.herrmann.com/form.html

    Code:
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    
    <script language="Javascript">
    
    var _iCounter =0;
    
    function AddElement() {
    	
    	_iCounter += 1;
    	
    	if (_iCounter <= 15) {
    		var o = document.getElementById("txtBoxHolder");
    		var txtFld = document.createElement("input");
    		txtFld.setAttribute("type","text");
    		txtFld.setAttribute("name","txtNew")
    		//txtDT.setAttribute("value",o.innerText);
    		
    		o.appendChild(txtFld);
    	} 
    	else {
    		alert("Sorry but no more fields can be added (15 is the Max).");
    	}
    
    }
    </script>
    </HEAD>
    
    <BODY>
    <form>
    Add a Textbox:<input type="button" value="+" onClick="AddElement()"><br/>
    <p id="txtBoxHolder" style="width:25px;"></p>
    
    </form>
    </BODY>
    </HTML>
    I want this code dynamically generate two form fields plus some HTML like the following: http://clients.herrmann.com/form2.html

    Can anyone get me started on how to do this? I write PHP , but still don't know much about Javascript. Any help is greatly appreciated.

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you can create a table row and store the elements into..
    so u just generate a table row with inputs inside..
    cheers


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
  •