this is dynamic rows code.when i click remove(-) any row i need to get respective checkbox id;

for example when i delete row3 i need to get checkbox id as houseCheck3;when i delete row2 i need to get checkbox id as houseCheck2;
once i get the id of that checkbox its easy for me to get the value;

<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
 </HEAD>
   <BODY>
 
   
  <script>
 table=document.createElement("table");
	table.setAttribute("id","TableA");
	table.setAttribute("border","0");
	table.setAttribute("width","50%");
	table.bgColor="lightblue"
    body = document.createElement("tbody");
 
    row =document.createElement("tr");
	    cell11 =document.createElement("td");
    cell11.appendChild(document.createTextNode(''));
	cell11.setAttribute("width","5%");
    row.appendChild(cell11);
 
    cell0 =document.createElement("td");
    cell0.appendChild(document.createTextNode('Sno'));
	cell0.setAttribute("id","Sno");
	cell0.setAttribute("width","5%");
    row.appendChild(cell0);
 
 
    cell1 =document.createElement("td");
    cell1.appendChild( document.createTextNode('ContainerType'));
	cell1.setAttribute("width","10%");
	cell1.setAttribute("font-style" ,"italic");
    row.appendChild(cell1);
 
   cell2 =document.createElement("td");
   cell2.setAttribute("width","10%");
    cell2.appendChild( document.createTextNode('ContainerNumber'));
    row.appendChild(cell2);
 
	cell3 =document.createElement("td");
	cell3.setAttribute("width","20%");
    cell3.appendChild( document.createTextNode('ContainerDescription'));
    row.appendChild(cell3);
	body.appendChild(row);
 
dynamicRows =function ()
{
  
		
     form = (( document.getElementById ) ? document.getElementById("frm") : document.all.frm );
    form.appendChild(table);
 
	row1 =document.createElement("tr");
 
 
    cell10 =document.createElement("td");
	check= document.createElement("input");
	check.setAttribute("type","checkbox");
	check.setAttribute("name","houseCheck");
	check.setAttribute("id","houseCheck1");
	check.setAttribute("value",'1');
 
	check.onclick= function(){ handleSelectedCheckBox(this); }
 
    cell10.appendChild(check);
 
    form.appendChild(cell10);
    row1.appendChild(cell10);
 
 
    cell8 =document.createElement("td");
	cell8.appendChild(document.createTextNode('1'));
	row1.appendChild(cell8);
 
 
 
    cell4 =document.createElement("td");
	select =document.createElement("select");
	select.setAttribute("name","ContainerType");
	select.setAttribute("id","ContainerType0");
 
	option =document.createElement("option");
	option.setAttribute("value","20F");
	option.appendChild(document.createTextNode("20F"));
	select.appendChild(option);
	    form.appendChild(select);
 
 
	option =document.createElement("option");
	option.setAttribute("value","40H");
	option.appendChild(document.createTextNode("40H"));
	select.appendChild(option);
   form.appendChild(select);
	option =document.createElement("option");
	option.setAttribute("value","60L");
	option.appendChild(document.createTextNode("60L"));
	select.appendChild(option);
     form.appendChild(select);
	option =document.createElement("option");
	option.setAttribute("value","80M");
	option.appendChild(document.createTextNode("80M"));
	select.appendChild(option);
    form.appendChild(select);
    cell4.appendChild(select);
    row1.appendChild(cell4);
 
    cell5 =document.createElement("td");
	ContainerInput= document.createElement("input");
	ContainerInput.setAttribute("type","text");
	ContainerInput.setAttribute("name","ContainerNumber");
	ContainerInput.setAttribute("id","ContainerNumber");
	ContainerInput.setAttribute("value",'CONATIONER156');
    cell5.appendChild(ContainerInput);
    form.appendChild(cell5);
 
    row1.appendChild(cell5);
 
 
    cell6 =document.createElement("td");
	ContainerDesc= document.createElement("input");
	ContainerDesc.setAttribute("type","text");
	ContainerDesc.setAttribute("name","ContainerDescription");
	ContainerInput.setAttribute("id","ContainerDescription");
	ContainerDesc.setAttribute("value",'TU');
 
    cell6.appendChild(ContainerDesc);
    form.appendChild(cell6);
    row1.appendChild(cell6);
 
	cell7 =document.createElement("td");
	add= document.createElement("input");
	add.setAttribute("type","button");
	add.setAttribute("name","add");
	add.setAttribute("value","+");
	add.onclick = function(){ addRow(); }
    cell7.appendChild(add);
	 form.appendChild(cell7);
 
    row1.appendChild(cell7);
 
		if(document.getElementById('TableA').rows.length >1)
		{
			 cell9 =document.createElement("td");
			remove= document.createElement("input");
			remove.setAttribute("type","button");
			remove.setAttribute("id","remove");
			remove.setAttribute("name","remove");
			remove.setAttribute("value","-");
	
			remove.onclick = function(){  
					removeRow(this);
			};
 
 
			cell9.appendChild(remove);
			row1.appendChild(cell9);
		}
		 	body.appendChild(row1);
 
		if(document.getElementById('ContainerType0'))
				{
		
			for (j=0;j<document.getElementById('ContainerType0').length;j++)
						  {
							   if ('20F' == document.getElementById('ContainerType0').options[j].value)
							   {
									document.getElementById('ContainerType0').options[j].selected = true;  
								     break;
							   }
						  }
				}
 
     form = (( document.getElementById ) ? document.getElementById("frm") : document.all.frm );
    form.appendChild(table);
 
	row1 =document.createElement("tr");
 
 
    cell10 =document.createElement("td");
	check= document.createElement("input");
	check.setAttribute("type","checkbox");
	check.setAttribute("name","houseCheck");
	check.setAttribute("id","houseCheck2");
	check.setAttribute("value",'2');
 
 
	check.onclick= function(){ handleSelectedCheckBox(this); }
 
    cell10.appendChild(check);
 
    form.appendChild(cell10);
    row1.appendChild(cell10);
 
 
    cell8 =document.createElement("td");
	cell8.appendChild(document.createTextNode('2'));
	row1.appendChild(cell8);
 
 
 
    cell4 =document.createElement("td");
	select =document.createElement("select");
	select.setAttribute("name","ContainerType");
	select.setAttribute("id","ContainerType1");
 
	option =document.createElement("option");
	option.setAttribute("value","20F");
	option.appendChild(document.createTextNode("20F"));
	select.appendChild(option);
	    form.appendChild(select);
 
 
	option =document.createElement("option");
	option.setAttribute("value","40H");
	option.appendChild(document.createTextNode("40H"));
	select.appendChild(option);
   form.appendChild(select);
	option =document.createElement("option");
	option.setAttribute("value","60L");
	option.appendChild(document.createTextNode("60L"));
	select.appendChild(option);
     form.appendChild(select);
	option =document.createElement("option");
	option.setAttribute("value","80M");
	option.appendChild(document.createTextNode("80M"));
	select.appendChild(option);
    form.appendChild(select);
    cell4.appendChild(select);
    row1.appendChild(cell4);
 
    cell5 =document.createElement("td");
	ContainerInput= document.createElement("input");
	ContainerInput.setAttribute("type","text");
	ContainerInput.setAttribute("name","ContainerNumber");
	ContainerInput.setAttribute("id","ContainerNumber");
	ContainerInput.setAttribute("value",'CONATIONER14444');
    cell5.appendChild(ContainerInput);
    form.appendChild(cell5);
 
    row1.appendChild(cell5);
 
 
    cell6 =document.createElement("td");
	ContainerDesc= document.createElement("input");
	ContainerDesc.setAttribute("type","text");
	ContainerDesc.setAttribute("name","ContainerDescription");
	ContainerInput.setAttribute("id","ContainerDescription");
	ContainerDesc.setAttribute("value",'TUT');
 
    cell6.appendChild(ContainerDesc);
    form.appendChild(cell6);
    row1.appendChild(cell6);
 
	cell7 =document.createElement("td");
	add= document.createElement("input");
	add.setAttribute("type","button");
	add.setAttribute("name","add");
	add.setAttribute("value","+");
	add.onclick = function(){ addRow(); }
    cell7.appendChild(add);
	 form.appendChild(cell7);
 
    row1.appendChild(cell7);
 
		if(document.getElementById('TableA').rows.length >1)
		{
			 cell9 =document.createElement("td");
			remove= document.createElement("input");
			remove.setAttribute("type","button");
			remove.setAttribute("id","remove");
			remove.setAttribute("name","remove");
			remove.setAttribute("value","-");
	
			remove.onclick = function(){  
					removeRow(this);
			};
 
 
			cell9.appendChild(remove);
			row1.appendChild(cell9);
		}
		 	body.appendChild(row1);
 
		if(document.getElementById('ContainerType1'))
				{
		
			for (j=0;j<document.getElementById('ContainerType1').length;j++)
						  {
							   if ('40H' == document.getElementById('ContainerType1').options[j].value)
							   {
									document.getElementById('ContainerType1').options[j].selected = true;  
								     break;
							   }
						  }
				}
 
     form = (( document.getElementById ) ? document.getElementById("frm") : document.all.frm );
    form.appendChild(table);
 
	row1 =document.createElement("tr");
 
 
    cell10 =document.createElement("td");
	check= document.createElement("input");
	check.setAttribute("type","checkbox");
	check.setAttribute("name","houseCheck");
	check.setAttribute("id","houseCheck3");
	check.setAttribute("value",'3');
 
 
	check.onclick= function(){ handleSelectedCheckBox(this); }
 
    cell10.appendChild(check);
 
    form.appendChild(cell10);
    row1.appendChild(cell10);
 
 
    cell8 =document.createElement("td");
	cell8.appendChild(document.createTextNode('3'));
	row1.appendChild(cell8);
 
 
 
    cell4 =document.createElement("td");
	select =document.createElement("select");
	select.setAttribute("name","ContainerType");
	select.setAttribute("id","ContainerType2");
 
	option =document.createElement("option");
	option.setAttribute("value","20F");
	option.appendChild(document.createTextNode("20F"));
	select.appendChild(option);
	    form.appendChild(select);
 
 
	option =document.createElement("option");
	option.setAttribute("value","40H");
	option.appendChild(document.createTextNode("40H"));
	select.appendChild(option);
   form.appendChild(select);
	option =document.createElement("option");
	option.setAttribute("value","60L");
	option.appendChild(document.createTextNode("60L"));
	select.appendChild(option);
     form.appendChild(select);
	option =document.createElement("option");
	option.setAttribute("value","80M");
	option.appendChild(document.createTextNode("80M"));
	select.appendChild(option);
    form.appendChild(select);
    cell4.appendChild(select);
    row1.appendChild(cell4);
 
    cell5 =document.createElement("td");
	ContainerInput= document.createElement("input");
	ContainerInput.setAttribute("type","text");
	ContainerInput.setAttribute("name","ContainerNumber");
	ContainerInput.setAttribute("id","ContainerNumber");
	ContainerInput.setAttribute("value",'CONATIONER14766');
    cell5.appendChild(ContainerInput);
    form.appendChild(cell5);
 
    row1.appendChild(cell5);
 
 
    cell6 =document.createElement("td");
	ContainerDesc= document.createElement("input");
	ContainerDesc.setAttribute("type","text");
	ContainerDesc.setAttribute("name","ContainerDescription");
	ContainerInput.setAttribute("id","ContainerDescription");
	ContainerDesc.setAttribute("value",'6gjgj');
 
    cell6.appendChild(ContainerDesc);
    form.appendChild(cell6);
    row1.appendChild(cell6);
 
	cell7 =document.createElement("td");
	add= document.createElement("input");
	add.setAttribute("type","button");
	add.setAttribute("name","add");
	add.setAttribute("value","+");
	add.onclick = function(){ addRow(); }
    cell7.appendChild(add);
	 form.appendChild(cell7);
 
    row1.appendChild(cell7);
 
		if(document.getElementById('TableA').rows.length >1)
		{
			 cell9 =document.createElement("td");
			remove= document.createElement("input");
			remove.setAttribute("type","button");
			remove.setAttribute("id","remove");
			remove.setAttribute("name","remove");
			remove.setAttribute("value","-");
	
			remove.onclick = function(){  
					removeRow(this);
			};
 
 
			cell9.appendChild(remove);
			row1.appendChild(cell9);
		}
		 	body.appendChild(row1);
 
		if(document.getElementById('ContainerType2'))
				{
		
			for (j=0;j<document.getElementById('ContainerType2').length;j++)
						  {
							   if ('40H' == document.getElementById('ContainerType2').options[j].value)
							   {
									document.getElementById('ContainerType2').options[j].selected = true;  
								     break;
							   }
						  }
				}
 
 
 
}
 
	table.appendChild(body);
    document.body.appendChild(table);
    window.onload = dynamicRows;
		
 
 function addRow()
  {
	 dynamicRows();
  }
function removeRow(theRow){
 
 
		var tab=document.getElementById('TableA');
		index= theRow.parentNode.parentNode.rowIndex;
		tab.deleteRow(index);
 
 
}
 
 
  </script>
     <form id="frm"  name="frm" >
	<input type="submit" name="submit" value="submit">
 
 </form>
 
 </BODY>
</HTML>

Recommended Answers

All 3 Replies

Hi
Change the removeRow() to the following.. This will alert the checkbox id.
(You have to take the check box id before deleting the table row)

  function removeRow(theRow){ 
        var rowObj = theRow.parentNode.parentNode;
        var chkObj = rowObj.cells[0].childNodes[0];
        alert(chkObj.id);
        var tab=document.getElementById('TableA');
        index= theRow.parentNode.parentNode.rowIndex;
        tab.deleteRow(index);
}

Regards
Anish

Hi
Change the removeRow() to the following.. This will alert the checkbox id.
(You have to take the check box id before deleting the table row)

  function removeRow(theRow){ 
        var rowObj = theRow.parentNode.parentNode;
        var chkObj = rowObj.cells[0].childNodes[0];
        alert(chkObj.id);
        var tab=document.getElementById('TableA');
        index= theRow.parentNode.parentNode.rowIndex;
        tab.deleteRow(index);
}

Regards
Anish

when i put alert(chkObj.id); its coming as blank.Please check it once.

Hi
No issues found.I am getting check box id inside the alert box..Did you change the removeRow()? Try out this code

<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
 </HEAD>
   <BODY>


  <script>
 table=document.createElement("table");
    table.setAttribute("id","TableA");
    table.setAttribute("border","0");
    table.setAttribute("width","50%");
    table.bgColor="lightblue"
    body = document.createElement("tbody");

    row =document.createElement("tr");
        cell11 =document.createElement("td");
    cell11.appendChild(document.createTextNode(''));
    cell11.setAttribute("width","5%");
    row.appendChild(cell11);

    cell0 =document.createElement("td");
    cell0.appendChild(document.createTextNode('Sno'));
    cell0.setAttribute("id","Sno");
    cell0.setAttribute("width","5%");
    row.appendChild(cell0);


    cell1 =document.createElement("td");
    cell1.appendChild( document.createTextNode('ContainerType'));
    cell1.setAttribute("width","10%");
    cell1.setAttribute("font-style" ,"italic");
    row.appendChild(cell1);

   cell2 =document.createElement("td");
   cell2.setAttribute("width","10%");
    cell2.appendChild( document.createTextNode('ContainerNumber'));
    row.appendChild(cell2);

    cell3 =document.createElement("td");
    cell3.setAttribute("width","20%");
    cell3.appendChild( document.createTextNode('ContainerDescription'));
    row.appendChild(cell3);
    body.appendChild(row);

dynamicRows =function ()
{


     form = (( document.getElementById ) ? document.getElementById("frm") : document.all.frm );
    form.appendChild(table);

    row1 =document.createElement("tr");


    cell10 =document.createElement("td");
    check= document.createElement("input");
    check.setAttribute("type","checkbox");
    check.setAttribute("name","houseCheck");
    check.setAttribute("id","houseCheck1");
    check.setAttribute("value",'1');

    check.onclick= function(){ handleSelectedCheckBox(this); }

    cell10.appendChild(check);

    form.appendChild(cell10);
    row1.appendChild(cell10);


    cell8 =document.createElement("td");
    cell8.appendChild(document.createTextNode('1'));
    row1.appendChild(cell8);



    cell4 =document.createElement("td");
    select =document.createElement("select");
    select.setAttribute("name","ContainerType");
    select.setAttribute("id","ContainerType0");

    option =document.createElement("option");
    option.setAttribute("value","20F");
    option.appendChild(document.createTextNode("20F"));
    select.appendChild(option);
        form.appendChild(select);


    option =document.createElement("option");
    option.setAttribute("value","40H");
    option.appendChild(document.createTextNode("40H"));
    select.appendChild(option);
   form.appendChild(select);
    option =document.createElement("option");
    option.setAttribute("value","60L");
    option.appendChild(document.createTextNode("60L"));
    select.appendChild(option);
     form.appendChild(select);
    option =document.createElement("option");
    option.setAttribute("value","80M");
    option.appendChild(document.createTextNode("80M"));
    select.appendChild(option);
    form.appendChild(select);
    cell4.appendChild(select);
    row1.appendChild(cell4);

    cell5 =document.createElement("td");
    ContainerInput= document.createElement("input");
    ContainerInput.setAttribute("type","text");
    ContainerInput.setAttribute("name","ContainerNumber");
    ContainerInput.setAttribute("id","ContainerNumber");
    ContainerInput.setAttribute("value",'CONATIONER156');
    cell5.appendChild(ContainerInput);
    form.appendChild(cell5);

    row1.appendChild(cell5);


    cell6 =document.createElement("td");
    ContainerDesc= document.createElement("input");
    ContainerDesc.setAttribute("type","text");
    ContainerDesc.setAttribute("name","ContainerDescription");
    ContainerInput.setAttribute("id","ContainerDescription");
    ContainerDesc.setAttribute("value",'TU');

    cell6.appendChild(ContainerDesc);
    form.appendChild(cell6);
    row1.appendChild(cell6);

    cell7 =document.createElement("td");
    add= document.createElement("input");
    add.setAttribute("type","button");
    add.setAttribute("name","add");
    add.setAttribute("value","+");
    add.onclick = function(){ addRow(); }
    cell7.appendChild(add);
     form.appendChild(cell7);

    row1.appendChild(cell7);

        if(document.getElementById('TableA').rows.length >1)
        {
             cell9 =document.createElement("td");
            remove= document.createElement("input");
            remove.setAttribute("type","button");
            remove.setAttribute("id","remove");
            remove.setAttribute("name","remove");
            remove.setAttribute("value","-");

            remove.onclick = function(){  
                    removeRow(this);
            };


            cell9.appendChild(remove);
            row1.appendChild(cell9);
        }
            body.appendChild(row1);

        if(document.getElementById('ContainerType0'))
                {

            for (j=0;j<document.getElementById('ContainerType0').length;j++)
                          {
                               if ('20F' == document.getElementById('ContainerType0').options[j].value)
                               {
                                    document.getElementById('ContainerType0').options[j].selected = true;  
                                     break;
                               }
                          }
                }

     form = (( document.getElementById ) ? document.getElementById("frm") : document.all.frm );
    form.appendChild(table);

    row1 =document.createElement("tr");


    cell10 =document.createElement("td");
    check= document.createElement("input");
    check.setAttribute("type","checkbox");
    check.setAttribute("name","houseCheck");
    check.setAttribute("id","houseCheck2");
    check.setAttribute("value",'2');


    check.onclick= function(){ handleSelectedCheckBox(this); }

    cell10.appendChild(check);

    form.appendChild(cell10);
    row1.appendChild(cell10);


    cell8 =document.createElement("td");
    cell8.appendChild(document.createTextNode('2'));
    row1.appendChild(cell8);



    cell4 =document.createElement("td");
    select =document.createElement("select");
    select.setAttribute("name","ContainerType");
    select.setAttribute("id","ContainerType1");

    option =document.createElement("option");
    option.setAttribute("value","20F");
    option.appendChild(document.createTextNode("20F"));
    select.appendChild(option);
        form.appendChild(select);


    option =document.createElement("option");
    option.setAttribute("value","40H");
    option.appendChild(document.createTextNode("40H"));
    select.appendChild(option);
   form.appendChild(select);
    option =document.createElement("option");
    option.setAttribute("value","60L");
    option.appendChild(document.createTextNode("60L"));
    select.appendChild(option);
     form.appendChild(select);
    option =document.createElement("option");
    option.setAttribute("value","80M");
    option.appendChild(document.createTextNode("80M"));
    select.appendChild(option);
    form.appendChild(select);
    cell4.appendChild(select);
    row1.appendChild(cell4);

    cell5 =document.createElement("td");
    ContainerInput= document.createElement("input");
    ContainerInput.setAttribute("type","text");
    ContainerInput.setAttribute("name","ContainerNumber");
    ContainerInput.setAttribute("id","ContainerNumber");
    ContainerInput.setAttribute("value",'CONATIONER14444');
    cell5.appendChild(ContainerInput);
    form.appendChild(cell5);

    row1.appendChild(cell5);


    cell6 =document.createElement("td");
    ContainerDesc= document.createElement("input");
    ContainerDesc.setAttribute("type","text");
    ContainerDesc.setAttribute("name","ContainerDescription");
    ContainerInput.setAttribute("id","ContainerDescription");
    ContainerDesc.setAttribute("value",'TUT');

    cell6.appendChild(ContainerDesc);
    form.appendChild(cell6);
    row1.appendChild(cell6);

    cell7 =document.createElement("td");
    add= document.createElement("input");
    add.setAttribute("type","button");
    add.setAttribute("name","add");
    add.setAttribute("value","+");
    add.onclick = function(){ addRow(); }
    cell7.appendChild(add);
     form.appendChild(cell7);

    row1.appendChild(cell7);

        if(document.getElementById('TableA').rows.length >1)
        {
             cell9 =document.createElement("td");
            remove= document.createElement("input");
            remove.setAttribute("type","button");
            remove.setAttribute("id","remove");
            remove.setAttribute("name","remove");
            remove.setAttribute("value","-");

            remove.onclick = function(){  
                    removeRow(this);
            };


            cell9.appendChild(remove);
            row1.appendChild(cell9);
        }
            body.appendChild(row1);

        if(document.getElementById('ContainerType1'))
                {

            for (j=0;j<document.getElementById('ContainerType1').length;j++)
                          {
                               if ('40H' == document.getElementById('ContainerType1').options[j].value)
                               {
                                    document.getElementById('ContainerType1').options[j].selected = true;  
                                     break;
                               }
                          }
                }

     form = (( document.getElementById ) ? document.getElementById("frm") : document.all.frm );
    form.appendChild(table);

    row1 =document.createElement("tr");


    cell10 =document.createElement("td");
    check= document.createElement("input");
    check.setAttribute("type","checkbox");
    check.setAttribute("name","houseCheck");
    check.setAttribute("id","houseCheck3");
    check.setAttribute("value",'3');


    check.onclick= function(){ handleSelectedCheckBox(this); }

    cell10.appendChild(check);

    form.appendChild(cell10);
    row1.appendChild(cell10);


    cell8 =document.createElement("td");
    cell8.appendChild(document.createTextNode('3'));
    row1.appendChild(cell8);



    cell4 =document.createElement("td");
    select =document.createElement("select");
    select.setAttribute("name","ContainerType");
    select.setAttribute("id","ContainerType2");

    option =document.createElement("option");
    option.setAttribute("value","20F");
    option.appendChild(document.createTextNode("20F"));
    select.appendChild(option);
        form.appendChild(select);


    option =document.createElement("option");
    option.setAttribute("value","40H");
    option.appendChild(document.createTextNode("40H"));
    select.appendChild(option);
   form.appendChild(select);
    option =document.createElement("option");
    option.setAttribute("value","60L");
    option.appendChild(document.createTextNode("60L"));
    select.appendChild(option);
     form.appendChild(select);
    option =document.createElement("option");
    option.setAttribute("value","80M");
    option.appendChild(document.createTextNode("80M"));
    select.appendChild(option);
    form.appendChild(select);
    cell4.appendChild(select);
    row1.appendChild(cell4);

    cell5 =document.createElement("td");
    ContainerInput= document.createElement("input");
    ContainerInput.setAttribute("type","text");
    ContainerInput.setAttribute("name","ContainerNumber");
    ContainerInput.setAttribute("id","ContainerNumber");
    ContainerInput.setAttribute("value",'CONATIONER14766');
    cell5.appendChild(ContainerInput);
    form.appendChild(cell5);

    row1.appendChild(cell5);


    cell6 =document.createElement("td");
    ContainerDesc= document.createElement("input");
    ContainerDesc.setAttribute("type","text");
    ContainerDesc.setAttribute("name","ContainerDescription");
    ContainerInput.setAttribute("id","ContainerDescription");
    ContainerDesc.setAttribute("value",'6gjgj');

    cell6.appendChild(ContainerDesc);
    form.appendChild(cell6);
    row1.appendChild(cell6);

    cell7 =document.createElement("td");
    add= document.createElement("input");
    add.setAttribute("type","button");
    add.setAttribute("name","add");
    add.setAttribute("value","+");
    add.onclick = function(){ addRow(); }
    cell7.appendChild(add);
     form.appendChild(cell7);

    row1.appendChild(cell7);

        if(document.getElementById('TableA').rows.length >1)
        {
             cell9 =document.createElement("td");
            remove= document.createElement("input");
            remove.setAttribute("type","button");
            remove.setAttribute("id","remove");
            remove.setAttribute("name","remove");
            remove.setAttribute("value","-");

            remove.onclick = function(){  
                    removeRow(this);
            };


            cell9.appendChild(remove);
            row1.appendChild(cell9);
        }
            body.appendChild(row1);

        if(document.getElementById('ContainerType2'))
                {

            for (j=0;j<document.getElementById('ContainerType2').length;j++)
                          {
                               if ('40H' == document.getElementById('ContainerType2').options[j].value)
                               {
                                    document.getElementById('ContainerType2').options[j].selected = true;  
                                     break;
                               }
                          }
                }



}

    table.appendChild(body);
    document.body.appendChild(table);
    window.onload = dynamicRows;


 function addRow()
  {
     dynamicRows();
  }

function removeRow(theRow){
    var rowObj = theRow.parentNode.parentNode;
    var chkObj = rowObj.cells[0].childNodes[0];
    alert(chkObj.id);
    var tab=document.getElementById('TableA');
    index= theRow.parentNode.parentNode.rowIndex;
    tab.deleteRow(index);
}


  </script>
     <form id="frm"  name="frm" >
    <input type="submit" name="submit" value="submit">

 </form>

 </BODY>
</HTML>

Regards
Anish

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.