wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes how to create form and form element dynamically? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "how to create form and form element dynamically?" Watch "how to create form and form element dynamically?" New topic
Author

how to create form and form element dynamically?

Abhishek Reddy
Ranch Hand

Joined: Mar 28, 2006
Posts: 259
Can any one tell me how to create form and form elements dynamically?
Once the form is ready, i have to submit it dynamically..

I have tried, but failed to get the expected result.

here is the code which i have tried..

function buildForm()
{
var form_ref=document.createElement("form");
form_ref.name="addform";
form_ref.action="a.jsp";
form_ref.method="post";
form_ref.target="new";

var hidden_element = document.createElement("input");
hidden_element.type="hidden";
hidden_element.name="id";
hidden_element.value="1";
form_ref.appendChild(hidden_element);

var submit_element = document.createElement("input");
submit_element.type="submit";
submit_element.name="submit";
submit_element.value="submit";
form_ref.appendChild(submit_element);


form_ref.submit();
}


Abhishek
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60774
    
  65

Please be sure to use UBB code tags when posting code to the forums. Unformatted code is extermely hard to read and many people that might be able to help you will just move along. Please read this for more information.

You can go back and change your post to add code tags by clicking the .


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60774
    
  65

At what point do you attach the form to the document?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You might want to look at creating elements this way. The name has issues being set in certain browsers. The code here:
http://www.pascarello.com/examples/createElement.html

fixes that browser quirk.

As Bear said you need to look into appendChild so the form is actually added to the page so you can submit it.

Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to create form and form element dynamically?
 
Similar Threads
Javascript DOM and tapestry 5
Dynamically added form fields cannot access from request access
Dynamically created {input type=file}
Submit popup
How can I struts tag library with in javascript ?