Forum Moderators: open

Message Too Old, No Replies

Dynamically create form using Javascript

         

jcmiras

12:55 pm on Jun 10, 2005 (gmt 0)

10+ Year Member



I am developing a part of my website that require a dynamic creation of forms (Just like in gmail.com when clicking the "attach another file" link) but the problem is, i dont know how to do it using javascript. Can anyone provide me a code that can do such thing. Thanks.

garann

7:03 pm on Jun 10, 2005 (gmt 0)

10+ Year Member



There are several ways to do it. One way is to add to the innerHTML of the form or some other containing element:

JS:
var obj = document.getElementById("myForm");
obj.innerHTML = obj.innerHTML + "Another File: <input type='file'>";

HTML:
<form id="myForm" method="POST">
One File: <input type="file">
</form>

You can also look into the use of createElement, which is more elegant but more of a pain.