Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,094
    Thanks
    15
    Thanked 1 Time in 1 Post

    Arrow insertRow innerHTML

    Code:
    for (u=1;u<=counter;u++)
    {
    	row = document.getElementById('demodiv_t').insertRow(-1)
    	cell = row.insertCell(-1)
    	cell.innerHTML = "<h6>TEST</h6>"
    }
    why does this not build only the number fo rows that the loop dictates.
    i.e. counter

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    what about a DOM1 solution?
    PHP Code:
    var oTab document.getElementById('demodiv_t');
    var 
    oTbo document.createElement('tbody');
    for(var 
    i=0;i<counter;i++){
    var 
    oTr document.createElement('tr');
    var 
    oTd document.createElement('td');
    var 
    oH document.createElement('h6');
    oH.appendChild(createTextNode('TEST'));
    oTd.appendChild(oH);oTr.appendChild(oTd);oTbo.appendChild(oTr)
    }
    oTab.appendChild(oTbo
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,094
    Thanks
    15
    Thanked 1 Time in 1 Post

    Arrow

    i build this table in js (innerHTML)
    Code:
    	row = document.getElementById('demodiv_t').insertRow()
    	//alert("a = " + a);	
    	cell = row.insertCell()
    	cell.innerHTML = headingArr[a].toProperCase()
    	cell2 = row.insertCell()
    	cell2.innerHTML = contentArr[a]
    but, when i click the link that runs this code it just adds more rows and doesnt replace
    the old ones??

  • #4
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,094
    Thanks
    15
    Thanked 1 Time in 1 Post
    Code:
    function build_rules(contract_id,heading,content,contracts,counter,records)
    {
    	//alert("ENTRE function build_rules");
    	if(window.onerror)
    	{
    		bError = true;
    	}
    	
    	// If the table has already been built for another
    	// CTC ID then empty the table and build new table for new CTC ID
    	if(tableComplete==true)
    	{
    		heading_str = "";
    		content_str = "";
    		headingArr = "";
    		contentArr = "";
    		//cell.innerHTML = "";
    		//cell2.innerHTML = "";
    		tableComplete=false;
    		//document.getElementById('demodiv_t').value="";
    		//delete_row = document.getElementById('demodiv_t').deleteRow()
    		//delete_cell = delete_row.deleteCell()
    		
    		var t = document.getElementById("demodiv_t");
    		//alert("t.rows.length = " + t.rows.length);
    		//no_of_rows = t.rows.length;
    		//no_of_rows = parseInt(no_of_rows+1);
    		//alert("no_of_rows = " + no_of_rows);
    		
    		if(rowsDeleted!=true)
    		{
    			for(r=0;r<t.rows.length;r++)
    			{
    				//alert("CONTROL r = " + r);
    				t.deleteRow(r);
    				rowsDeleted=true;
    			}
    		}
    		a=0;
    	}
    	
    	if(tableComplete!=true)
    	{
    		heading_str = heading_str + "~" + heading;
    		content_str = content_str + "~" + content;
    		
    		contentArr = content_str.split("~");
    		headingArr = heading_str.split("~");
    	
    	
    	div = document.getElementById('demodiv')
    	row = document.getElementById('demodiv_t').insertRow()
    	//alert("a = " + a);	
    	cell = row.insertCell()
    	cell.innerHTML = headingArr[a].toProperCase()
    	cell2 = row.insertCell()
    	cell2.innerHTML = contentArr[a]
    
    	bTableSetup = true;
    	a=a+1;
    	}
    }
    it seems to only delete some rows???


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •