Appending inputs to a form

Discussion in 'JavaScript' started by Greenmethod, Apr 6, 2010.

  1. #1
    I have them coming up on the page correctly, and they are all named correctly, but when I submit the form they aren't passed with post....

    JavaScript...
    function addItem(){
    	var itemTable = document.getElementById('itemTable');
    	var lastItem = document.getElementsByName('deleteItem');
    	var newRow = itemTable.rows.length-1;
    	var itemNum = itemTable.getElementsByClassName("item").length+1;
    	var row1 = itemTable.insertRow(newRow);
    	row1.className = "item";
    	
    	
    	//item number
    	var cellItemNum = row1.insertCell(0);
    	var textNode = document.createTextNode(itemNum);
    	cellItemNum.appendChild(textNode);
    	
    	//limOfLia
    	var cellLimofLia = row1.insertCell(1);
    	var el = document.createElement('input');
    	el.type = 'text';
    	el.name = 'item['+itemNum+'][limofLia]';
    	el.id = 'item['+itemNum+'][limofLia]';
    	el.size =7;
    	el.maxLength=12;
    	cellLimofLia.appendChild(document.createTextNode('$'));
    	cellLimofLia.appendChild(el);
    	cellLimofLia.appendChild(document.createTextNode('.00'));
    	
    	//coIns
    	var cellcoIns = row1.insertCell(2);
    	var el = document.createElement('input');
    	el.type = 'text';
    	el.name = 'item['+itemNum+'][coIns]';
    	el.id = 'item['+itemNum+'][coIns]';
    	el.size =1;
    	el.maxLength=2;
    	cellcoIns.appendChild(el);
    	cellcoIns.appendChild(document.createTextNode('%'));
    	
    	//deductable
    	var cellDeduct = row1.insertCell(3);
    	var el = document.createElement('input');
    	el.type = 'text';
    	el.name = 'item['+itemNum+'][deduct]';
    	el.id = 'item['+itemNum+'][deduct]';
    	el.size =5;
    	el.maxLength=12;
    	cellDeduct.appendChild(document.createTextNode('$'));
    	cellDeduct.appendChild(el);
    	cellDeduct.appendChild(document.createTextNode('.00'));
    	
    	//form1
    	var cellform1 = row1.insertCell(4);
    	var el = document.createElement('input');
    	el.type = 'text';
    	el.name = 'item['+itemNum+'][form1]';
    	el.id = 'item['+itemNum+'][form1]';
    	el.size =4;
    	el.maxLength=9;
    	cellform1.appendChild(el);
    	
    	//Property Description
    	var cellDesc = row1.insertCell(5);
    	var el = document.createElement('input');
    	el.type = 'text';
    	el.name = 'item['+itemNum+'][propDesc]';
    	el.id = 'item['+itemNum+'][propDesc]';
    	el.size =25;
    	el.maxLength=20;
    	cellDesc.appendChild(document.createTextNode('Description: '));
    	cellDesc.appendChild(el);
    	
    	var row2 = itemTable.insertRow(newRow+1);
    	
    	//form2
    	var blankform2 = row2.insertCell(0);
    	var blankform2 = row2.insertCell(1);
    	var blankform2 = row2.insertCell(2);
    	var blankform2 = row2.insertCell(3);
    	var cellform2 = row2.insertCell(4);
    	var el = document.createElement('input');
    	el.type = 'text';
    	el.name = 'item['+itemNum+'][form2]';
    	el.id = 'item['+itemNum+'][form2]';
    	el.size =4;
    	el.maxLength=9;
    	cellform2.appendChild(el);
    	
    	//Property Address
    	var cellAddr = row2.insertCell(5);
    	var el = document.createElement('input');
    	el.type = 'text';
    	el.name = 'item['+itemNum+'][propAddr]';
    	el.id = 'item['+itemNum+'][propAddr]';
    	el.size =25;
    	el.maxLength=20;
    	cellAddr.appendChild(document.createTextNode('Address: '));
    	cellAddr.appendChild(el);
    	
    	var row3 = itemTable.insertRow(newRow+2);
    	
    	//form2
    	var blank = row3.insertCell(0);
    	var blank = row3.insertCell(1);
    	var blank = row3.insertCell(2);
    	var blank = row3.insertCell(3);
    	var cellform3 = row3.insertCell(4);
    	var el = document.createElement('input');
    	el.type = 'text';
    	el.name = 'item['+itemNum+'][form3]';
    	el.id = 'item['+itemNum+'][form3]';
    	el.size =4;
    	el.maxLength=9;
    	cellform3.appendChild(el);
    	
    	//Property Occupancy
    	var cellOccu = row3.insertCell(5);
    	var el = document.createElement('input');
    	el.type = 'text';
    	el.name = 'item['+itemNum+'][propOccu]';
    	el.id = 'item['+itemNum+'][propOccu]';
    	el.size =25;
    	el.maxLength=20;
    	cellOccu.appendChild(document.createTextNode('Occupancy: '));
    	cellOccu.appendChild(el);
    }
    Code (markup):
    <table class="items" width="100%" id="itemTable" border="0">
    		<tr class="hed" id="under">
    			<td>Item</td>
    			<td>Lim</td>
    			<td>Co</td>
    			<td>Ded</td>
    			<td>Form<br />Numbers</td>
    			<td>Description</td>
    		</tr>
    	<tr>
    		<td colspan="6" align="right"></td>
    	</tr>
    </table>
    <input type="button" onclick="addItem();" value="Add Item">
    HTML:
     
    Greenmethod, Apr 6, 2010 IP
  2. d_s

    d_s Peon

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi,

    May be you should try by adding the input type controls instead of the textnodes.
    just give'em a try.

    if you need some sample code, you may get it from my blog at: http://www.dsaravanan.wordpress.com/javascript.

    regards
    d_s


     
    d_s, Apr 7, 2010 IP