Jump to content

Need Help Implementing A Dynamic Form


Guest vinceh
 Share

Recommended Posts

Guest vinceh

So basically what I want to do is have an "add" and "remove" button to add fields into my form. I don't know how to do it, and I'm been playing around with it for hours. Anyway, here is my code:

<html><head>    <script type="text/javascript">function add(area,limit){	// I have no idea what to put here}</script>     <style type="text/css" media="screen">      body {        background: #222;        color: #fff;        font: 80% verdana;        font-weight: normal;        margin: 0;        padding: 0 20 .5em 200;      }    </style></head><body></br></br></br></br></br></br>Variables: <form>	<p id="var">		Name = <input type="text" id="var1" /> <input type="button" value="Remove" id="button" /></br>		Name = <input type="text" id="var2" /> <input type="button" value="Remove" id="button" /></br>		Name = <input type="text" id="var3" /> <input type="button" value="Remove" id="button" /></br>		Name = <input type="text" id="var4" /> <input type="button" value="Remove" id="button" /></br>	</p>	<input type="button" onclick="add('var',0)" value="Add"  /></form></body></html>

The reason I enclosed my fields into a <p> is because I want to have different sections with different type of inputs that all belong to the same form. Should I not have done that?In the add function, even something like this doesn't work:

var root = document.getElementById(area);var insertee = document.createElement("element");insertee.type = "text";root.appendChild(insertee);

Can anyone give me any help?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...