Guest vinceh Posted June 18, 2009 Share Posted June 18, 2009 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 More sharing options...
justsomeguy Posted June 18, 2009 Share Posted June 18, 2009 The element to create isn't "element", it's "input". Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.