View Full Version : Dynamically add form elements
I'm trying to create an order form in the guise of a selection box, with accompanying field for quantity.
The way i would liek it to work is thus:
Select the product from the drop down box. Enter the quantity in the field.
Press the "Add" button to insert another row. For those of you that have used Gmail, its the same effect of adding another attachment, but adding two fields, a selection and a text field. Also, changing the form action to reflect the number of fields. e.g. submit.asp?q=4 for four rows, submit.asp?q=12 for 12 and so on.
Thanks for any help, sorry if this makes no sense... its late and i have a head cold - not a good combination.
10-04-2006, 05:16 AM
Once you add form elements, and if they are named, their value should be passed automatically via submission.
The best way to add form elements is via the DOM:
As I'm not sure of all the specifics, here is a very basic working example:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<form name="myform" action="#">
<input type="submit" value="submit">
<input type="text" name="art" onchange="add_input();">
Thanks for the reply. I really dont knwo what i'm doing with JS, so if you dont mind i'll pick your brains a little more...
How do i specify the type of form element i'm adding? I want ti to add both a select box with some 50 options or so, and a text field.
I'd also like them to be named select1, text1... select2, text2... select3, text3... etc for ease of processing with the form.
10-06-2006, 05:34 AM
That's a lot of creation. To create any particular element, use its tag name. With inputs, the type attribute may be defined (I left that out of my initial script as 'text' appears to be the default type). Children should be created before parents and then appended to their parent:
One or more arrays and counting variables could be set up to keep track of the options, selects, and text inputs, their names, values and whatever. Depending upon what each would be, arrays,variables or creation functions could be established for some or all of them so that they would be at the ready when needed rather than having to be individually created from scratch each time.
06-07-2008, 07:21 AM
want to design a html form. it will contain two text areas at the top as a parent.
whenever i click on add button it should again add two text areas to to the parent. This first child element will contain again add button to add two more text areas (first child's first child element) to first child element. Like this parent element can have any number of child elements, and again these child elements can have any number of child elements. [here each element is considered as two text areas]. There should also be facility to remove these elements. Actually trying to do it but i am not getting how to do it.. Please anyone help me.
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.