views:

48

answers:

6

Hi guys, how can I go about creating a form with javascript?

I have NO idea on how to proceed, I have been googling my face off but there is nothing definitive that can show me how to dynamically create forms with it.

Thanx in advance!

A: 

use document.write or if you want more flexibility use jquery

zaynyatyi
+1  A: 

I think posting a complete solution would be too much, but check out jQuery for this. I give you a hint, this could be very useful for you :)

yan.kun
A: 

Just use the standard DOM API (document.createElement(), see these docs for an example) to create all the elements of the form.

Aaron Digulla
A: 

My recommendation would be to get the underscore.js library and use its template function to create your forms. (If underscore is too large for you, the template function can stand on its own too).

Sean Vieira
+1  A: 

Yes, you can create any amount of html including forms by running javascript,

Perhaps:`

<html>
  <body>
    <h1>My Form</h1>
    <div id="formcontent">
    </div>
  </body>
</html>

Our javascript might look like:

var e1 = document.CreateElement("input");
el.type = "text";
el.name = "myformvar";

var cont = document.GetElementById("formcontent")
cont.appendChild(e1);
IanNorton