View Full Version : Javascript Dynamic Input Box Generatation
drewbe121212
Aug 7th 2006, 9:02 pm
Hello all, I have been trying to get something to work, but have come not anywhere near what I want to do. Basically, I have a list of input boxes, i need to push a button to "add another input box". I have tried several different ways, and failed each time. I have decided that innerHTML is not a feasible solution for this particular case.
The biggest problem I have is that when a user clicks the "add more fields" button, I can add a count++ to the current amount of inputs, or add another field to an array. The only problem is how to recycle through this without re-writing everything over again? If anyone has any good tutorials that they know of to look at, please feel more then free to let me know!
Thanks,
Drew
giraph
Aug 8th 2006, 8:57 am
<script type="text/javascript">
function addInput()
{
var x = document.getElementById("inputs");
x.innerHTML += "<input type=\"text\" />";
}
</script>
<input type="button" onmousedown="addInput();" />
<div id="inputs"></div>
mjamesb
Aug 13th 2006, 11:01 am
The most reliable way to do this without using .innerHTML is to use the DOM. If you do a search on "document.createElement" you should find many tutorials. It is a bit more coding than using .innerHTML but you can do a lot using the DOM instead.
drewbe121212
Aug 14th 2006, 7:16 am
I actually had alot of problems figuring this out. I now went a server side solution / javascript. While the input boxes are determined server side (page reload), the preview of what everything is going to look like is done through javascript. Thank you for the heads up on the DOM as well. I cannot wait until innerHTML = standard :)
saneinsight
Mar 4th 2007, 11:51 am
hi giraph, thanks for the great example code. how do I actually reference the new input fields? Usually I'd get the param within a perl cgi script.
thanks
Sane
love_bug
Oct 7th 2008, 9:36 am
hi nice script, I am looking for exactly the same solution...
if you could show how to increase field name also.. such as "field1", field2, field3
it would be greatly appreciated.
thanks..
Logic Ali
Oct 9th 2008, 6:52 pm
hi nice script, I am looking for exactly the same solution...
if you could show how to increase field name also.. such as "field1", field2, field3
it would be greatly appreciated.
thanks..Try FieldClone (http://scripterlative.com/?fieldclone) which has name incrementation technology.
jgarrison
Oct 13th 2008, 6:50 pm
hi nice script, I am looking for exactly the same solution...
if you could show how to increase field name also.. such as "field1", field2, field3
it would be greatly appreciated.
thanks..
Please see your other posting about this. http://forums.digitalpoint.com/showthread.php?t=1057277
Let me know if that's what you're looking for.
Thanks.
-Jim
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.