Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding new elements to a form

Status
Not open for further replies.

dwhalen

Programmer
Feb 22, 2002
105
CA
Hello,

I am trying to allow users to add elements to a form dynamically. Here is some of my code:


Code:
function createNewRow(tbody){

var td,tr;
var cost = quan * 100;

tbody = document.getElementById(tbody);

tr = tbody.insertRow(tbody.rows.length);


//Product Name
td = tr.insertCell(tr.cells.length);
td.innerHTML = &quot;<input type='text name='product_name' value='Product &quot; + row+&quot;'>&quot;;


//Product quantity
td = tr.insertCell(tr.cells.length);
td.innerHTML = &quot;<input type='text' name='product_quantity' value=''>&quot;;

//Product quantity units
td = tr.insertCell(tr.cells.length);
td.innerHTML = &quot;<input type='text' name='product_units' value='feet'>&quot;;

//Product Price
td = tr.insertCell(tr.cells.length);
td.innerHTML = &quot;<input type='text' name='product_units' value='100'>&quot;;

//Product Curr
td = tr.insertCell(tr.cells.length);
td.innerHTML = &quot;<input type='text' name='product_units' value='CAD'>&quot;;

//Product Total
td = tr.insertCell(tr.cells.length);
td.innerHTML = &quot;<input type='text' name='product_units' value=''>&quot;;


row++;
quan++;
}
[\code]


This is not how it is going to work in the end cause I am just testing here to get the code base down.  The table that I am adding to is within a form.  However, when I post the form to a CGI script to print out all my form elements only the form elements that are present onload show up, not the ones created dynamically with the function above.  So any elements that are created by the user pressing a button, do not post.  Do I have to explicitly add the elements to the form?  If so, how do I do that?

Thanks

P.S. 

I hope I was clear on what I am doing.
 
Sorry, sorry, I figured it out! In my function I was naming each new element with the same name so now I do:

Code:
function createNewRow(tbody){

var td,tr;
var cost = quan * 100;

tbody = document.getElementById(tbody);

tr = tbody.insertRow(tbody.rows.length);

//Product Name
td = tr.insertCell(tr.cells.length);
td.innerHTML = &quot;<input type='text name='&quot;+row+&quot;product_name' value='Product &quot; + row+&quot;'>&quot;;


//Product quantity
td = tr.insertCell(tr.cells.length);
td.innerHTML = &quot;<input type='text' name='&quot;+row+&quot;product_quantity' value=''>&quot;;

//Product quantity units
td = tr.insertCell(tr.cells.length);
td.innerHTML = &quot;<input type='text' name='&quot;+row+&quot;product_units' value='feet'>&quot;;

//Product Price
td = tr.insertCell(tr.cells.length);
td.innerHTML = &quot;<input type='text' name='&quot;+row+&quot;product_price' value='100'>&quot;;

//Product Curr
td = tr.insertCell(tr.cells.length);
td.innerHTML = &quot;<input type='text' name='&quot;+row+&quot;product_curr' value='CAD'>&quot;;

//Product Total
td = tr.insertCell(tr.cells.length);
td.innerHTML = &quot;<input type='text' name='&quot;+row+&quot;product_total' value=''>&quot;;



row++;
quan++;
}

[\code]

Just a bad copy and paste mistake!! 

Later
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top