4 Replies - 6117 Views - Last Post: 27 June 2009 - 05:02 PM

#1 TechWar  Icon User is offline

  • D.I.C Regular

Reputation: 7
  • View blog
  • Posts: 470
  • Joined: 17-February 09

need to create a table in a div dynamically with js

Posted 27 June 2009 - 12:21 AM

I've got 2 div's and the first one has a form in it.
I want to create a table with the results of the form results in the second div.
It currently erases the page to create the table

Any help would be great. I don't use js too much, but for this job, I need to use it

Thanks
Is This A Good Question/Topic? 0
  • +

Replies To: need to create a table in a div dynamically with js

#2 BetaWar  Icon User is online

  • #include "soul.h"
  • member icon

Reputation: 1155
  • View blog
  • Posts: 7,167
  • Joined: 07-September 06

Re: need to create a table in a div dynamically with js

Posted 27 June 2009 - 12:36 AM

Well, you could make theHTML for the table then put it in the div based on its ID and using document.getElementById("IDHERE"); to get the object (div you want to put the table in), then use the innerHTML variable to se the object's inner HTML to the tble HTML.

Well, it is late, and I am not qquite sure tht makes any sense, so I'll check back in the morning.
Was This Post Helpful? 0
  • +
  • -

#3 TechWar  Icon User is offline

  • D.I.C Regular

Reputation: 7
  • View blog
  • Posts: 470
  • Joined: 17-February 09

Re: need to create a table in a div dynamically with js

Posted 27 June 2009 - 12:57 AM

testDiv.innerHTML='<table><tr><td><strong>Month</strong></td><td><strong>Principle</strong></td><td><strong>Payment</strong></td></tr>';


This is what I did, but it's not working

thanks for helping
Was This Post Helpful? 0
  • +
  • -

#4 TechWar  Icon User is offline

  • D.I.C Regular

Reputation: 7
  • View blog
  • Posts: 470
  • Joined: 17-February 09

Re: need to create a table in a div dynamically with js

Posted 27 June 2009 - 01:23 AM

testDiv.appendChild(document.createTextNode('<table><tr><td><strong>Month</strong></td><td><strong>Principle</strong></td><td><strong>Payment</strong></td></tr>'));
	
	while(tblPrinciple>0){
			
			testDiv.appendChild(document.createTextNode("<tr><td>"+curMonth+"/"+curYear+"</td><td>"+formatCurrency(tblPrinciple)+"</td><td>"+formatCurrency(pymnt)+"</td></tr>"));
			mnthlyRate=(tblPrinciple*intRate);
			tblPrinciple=tblPrinciple-(pymnt-mnthlyRate)-MonthlyDed;
			tblPrinciple=tblPrinciple-OneTime;
			OneTime=0;
			
			if (YearlyDed!=0 && YearlyMth==curMonth){
				tblPrinciple=(tblPrinciple-YearlyDed);
			}
			if (curMonth==12){
				curMonth=1;
				curYear++;
			}
			else{
				curMonth++;
			}//end if
	} //end while
	
	testDiv.appendChild(document.createTextNode("</table>"));



This is the code I've got and all it does is print the html code across the page instead of building my table.

Thanks for any help
Was This Post Helpful? 0
  • +
  • -

#5 TechWar  Icon User is offline

  • D.I.C Regular

Reputation: 7
  • View blog
  • Posts: 470
  • Joined: 17-February 09

Re: need to create a table in a div dynamically with js

Posted 27 June 2009 - 05:02 PM

Nevermind, I got it working today.
Thanks anyway though. :^:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1