Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 1 of 1
  1. #1
    Junior Member
    Join Date
    May 2009
    Posts
    1
    Member #
    19027
    Hi, I'm trying to display a table, and each time the user enters infomation in a prompt the table is updated. But when I run the code I have to go to the end before the table displays everthing.

    Code:
         // get the reference for the body
            var body = document.getElementsByTagName("body")[0]
            // creates a <table> element and a <tbody> element
            var tbl     = document.createElement("table")
            var tblBody = document.createElement("tbody")
     
    
     var row = document.createElement("tr")
     var cell = document.createElement("td")
     var cellText = document.createTextNode("Name")
     cell.appendChild(cellText)
     row.appendChild(cell)
    var cell = document.createElement("td")
     var cellText = document.createTextNode("Amount")
     cell.appendChild(cellText)
     row.appendChild(cell)
     
    var cell = document.createElement("td")
     var cellText = document.createTextNode("Tax Bracket")
     cell.appendChild(cellText)
     row.appendChild(cell)
     
    var cell = document.createElement("td")
     var cellText = document.createTextNode("Tax Amount")
     cell.appendChild(cellText)
     row.appendChild(cell)
     
    
    tblBody.appendChild(row);
         
     // put the <tbody> in the <table>
            tbl.appendChild(tblBody)
            // appends <table> into <body>
            body.appendChild(tbl)
            // sets the border attribute of tbl to 2
            tbl.setAttribute("border", "2")
     
     
    var answer=prompt("Enter amount for " + PEOPLE[0])
     
    
     var row = document.createElement("tr")
     var cell = document.createElement("td")
     var cellText = document.createTextNode(PEOPLE[0])
     cell.appendChild(cellText)
     row.appendChild(cell)
     
    
     var cell = document.createElement("td")
     var cellText = document.createTextNode(answer)
     cell.appendChild(cellText)
     row.appendChild(cell)
     
    tblBody.appendChild(row);
         
    
            // put the <tbody> in the <table>
            tbl.appendChild(tblBody);
            // appends <table> into <body>
            body.appendChild(tbl);
            // sets the border attribute of tbl to 2;
            tbl.setAttribute("border", "2");
     
     
    var answer=prompt("Enter amount for " + PEOPLE[1])
     
    
     var row = document.createElement("tr")
     var cell = document.createElement("td")
     var cellText = document.createTextNode(PEOPLE[1])
     cell.appendChild(cellText)
     row.appendChild(cell)
    How will I get it to display after each prompt.
    Thanks

  2.  


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 12:18 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com