Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9235331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:00:15+00:00 2026-06-18T07:00:15+00:00

The script i made loops and creates a table(s) based on user input, if

  • 0

The script i made loops and creates a table(s) based on user input, if super=2 then there should be 2 tables outputed with different numbers in the tables its working pretty well, except that it is printing the first table as it should, then when it does the second one, it reprints the fist one also.. any ideas?

code:

<html>
<head>

<script type="text/javascript">
function createTable()
{
var num_ports = document.getElementById('ports').value;
var num_super = document.getElementById('super').value;
var num_rows = document.getElementById('rows').value;
var num_cols = document.getElementById('cols').value;
var tbody = '';
var colStart = num_cols / num_super;
var y = 1;
for( var i = 1; i <= num_super; i++){
    var theader = '<div style="margin:0 auto;"><table border="1" style="border:1px solid black; float:left;">\n';
        for(u = 1; u <= num_rows; u++){
          tbody += '<tr>';
            for( var j = 1; j <= colStart; j++)
            {
            tbody += '<td style="width:80px; height:70px;">';
            tbody += '<sub style="float:right; position:relative; top:24px; z-index:11;  ">' + y + '</sub>';
            tbody += '</td>';
            y++;
            }
    tbody += '</tr>\n';
}
var tfooter = '</table></div>';
document.getElementById('wrapper').innerHTML += theader + tbody + tfooter;
}
}
</script>
</head>

<body>
<form name="tablegen">
<label>Ports: <input type="text" name="ports" id="ports"/></label><br />
<label>Super Columns: <input type="text" name="super" id="super"/></label><br />
<label>Rows: <input type="text" name="rows" id="rows"/></label><br />
<label>Columns: <input type="text" name="cols" id="cols"/></label><br/>
<input name="generate" type="button" value="Create Table!" onclick='createTable();'/>
</form>

<div id="wrapper"></div>
</body>
</html>

what i should look like:

should look like

what it is looking like:

bad table

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T07:00:17+00:00Added an answer on June 18, 2026 at 7:00 am

    Like the comment says – you clear tBody

    var tbody = '';
    

    before the loop , but that only happens once . Since it is delclared outside the loop , and never reset to ” , the contents of the first table are still in there for the second loop , try

    for( var i = 1; i <= num_super; i++){
        var tbody = '';
        //...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've made script which change information from different site, its occure when i click
What happes when the script that made @mysql_connect($server, $user, $password) dies? How long does
I have made a script that run various loops and does some SQL inserts.
Is there a jQuery plugin or JavaScript script that automagically loops through each CSS
The html of this script is made with list items http://www.jeremymartin.name/projects.php?project=kwicks Where can I
So I have a validation script I made a while ago. I can pass
Hey I was trying to call a script to made some changes to an
Im having a little trouble with a php script ive made. you can see
I made a script that crawls through a domain, and I want it to
I made a script that spawns a remote shell or runs a local shell

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.