View Full Version : How can I add a checkbox dynamically ?
Yovav
11-30-2002, 03:49 PM
Hi all.
how can I add a checkbox (or other form elements)
to a form that is already closed ( </FORM> )
is there something like formName.add()... ?
10X
smeagol
11-30-2002, 08:07 PM
To my knowledge, there is now form.add() method. The best way I know of to add form elements dynamically is to put the form elements on the form and set their style's visible property to "hidden". Then create a JavaScript function to change the element's visible property to "visible" when you want to show the form elements.
Adam20002
11-30-2002, 09:13 PM
Hi,
You can use the W3C DOM to dynamically add and remove things from the document including form elements.
Something like
var chk = document.createElement("INPUT");
chk.setAttribute("type","checkbox");
chk.setAttribute("name","myCheck");
document.yourform.appendChild(chk);
should work.
smeagol
12-01-2002, 05:12 AM
Hey Adam2002,
Great code! I never knew you could do that. Learn something new every day.
Smeagol
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.