Experience with Dynamically Creating Forms (JS)

Celeryman

Limp Gawd
Joined
Jan 16, 2003
Messages
418
Does anybody here have some experience or preferably some code samples that they have used to dynamically generate HTML forms with javascript and dom? Links to good tutorials would also be appreciated.
 
I would like to write a function so that when the user clicks on a button (or link), a js function is executed and adds whatever form element I specify to a div with the id of "form". I would also like to remove an element with a button or link that has been dynamically added.
 
OK, pretty much figured out my first question. Now I need to know how to loop through my dynamically created elements and get values from them such as the value of their id attribute.
 
Alright, figured out my last question as well. If for some reason somebody is interested in the code, LMK and I will post it.
 
Celeryman said:
OK, pretty much figured out my first question. Now I need to know how to loop through my dynamically created elements and get values from them such as the value of their id attribute.

assuming you have some function called doStuff that will take the value of each form element and do something with it.
Code:
for (i=0; i < document.forms[0].elements.length; i++) //get number of elements in the form
{
  doStuff(document.forms[0].elements[i].value);
}
 
Thank you for your help, but I figured it out. I will keep your code in mind though as I refine it.
 
Back
Top