School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,481 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,767 people online right now. Registration is fast and FREE... Join Now!




need to create a table in a div dynamically with js

 

need to create a table in a div dynamically with js

TechWar

26 Jun, 2009 - 11:21 PM
Post #1

D.I.C Regular
***

Joined: 17 Feb, 2009
Posts: 468



Thanked: 7 times
My Contributions
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

User is offlineProfile CardPM
+Quote Post


BetaWar

RE: Need To Create A Table In A Div Dynamically With Js

26 Jun, 2009 - 11:36 PM
Post #2

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 4,729



Thanked: 269 times
Dream Kudos: 1400
My Contributions
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.
User is offlineProfile CardPM
+Quote Post

TechWar

RE: Need To Create A Table In A Div Dynamically With Js

26 Jun, 2009 - 11:57 PM
Post #3

D.I.C Regular
***

Joined: 17 Feb, 2009
Posts: 468



Thanked: 7 times
My Contributions
CODE
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

User is offlineProfile CardPM
+Quote Post

TechWar

RE: Need To Create A Table In A Div Dynamically With Js

27 Jun, 2009 - 12:23 AM
Post #4

D.I.C Regular
***

Joined: 17 Feb, 2009
Posts: 468



Thanked: 7 times
My Contributions
CODE

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

User is offlineProfile CardPM
+Quote Post

TechWar

RE: Need To Create A Table In A Div Dynamically With Js

27 Jun, 2009 - 04:02 PM
Post #5

D.I.C Regular
***

Joined: 17 Feb, 2009
Posts: 468



Thanked: 7 times
My Contributions
Nevermind, I got it working today.
Thanks anyway though. icon_up.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 03:52AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month