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 9207977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:30:37+00:00 2026-06-18T00:30:37+00:00

I am trying to create a table based on user input (actually two or

  • 0

I am trying to create a table based on user input (actually two or three tables depending on the user input..) using Javascript, I am very much native to PHP and have already got this working in PHP, however i would like the user to be able to see the table before the query it. I found a script on here that partially did what I wanted and have attempted to edit it (I found it surprisingly similar to PHP) Basically it calculates the total amount of cells (ports) splits it by rows and columns, the “super” column is used if the user would like it to be split into multiple tables, which align next to each other, hence the div tag. Here’s my JS:

<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;
for( var i=0; i<num_super; i++){
    var theader = '<div><table border="1">\n';
        for(u=1; u<=num_row; u++){
          tbody += '<tr>';
            for( var j=0; j<colStart; j++)
            {
            tbody += '<td>';
            tbody += 'Cell ' + i + ',' + j;
            tbody += '</td>'
            }
    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>

Here is what the final output looks like after it has been processed by PHP (ports:24, col:6, rows:2, super:2):

table

Here is a js fiddle that I threw together:
http://jsfiddle.net/9SnLB/

Currently, when I click the button nothing happens, but, I suppose that is my first issue, but am I going about the setup correctly? Why wont the button run the function?

  • 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-18T00:30:38+00:00Added an answer on June 18, 2026 at 12:30 am

    Two mistakes. One you didn’t close the function bracket, ie a missing } at the end. The second is you used $row instead of the variable you created num_rows. For some reason it doesn’t work in the fiddle, it does however work locally. The fiddle is saying the createTable function is undefined.

    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;
        for( var i=0; i<num_super; i++){
            var theader = '<div><table border="1">\n';
                for($u=1; $u<=num_rows; $u++){
                  tbody += '<tr>';
                    for( var j=0; j<colStart; j++)
                    {
                    tbody += '<td>';
                    tbody += 'Cell ' + i + ',' + j;
                    tbody += '</td>'
                    }
            tbody += '</tr>\n';
        }
        var tfooter = '</table></div>';
        document.getElementById('wrapper').innerHTML = theader + tbody + tfooter;
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a table in MySQL based on user input. Ideally,
I'm trying to dynamically create a table based on user input, and it's working
I am trying to create a table with a single column using the following
I'm trying to query my database based on user input and I get this
I am trying to create a table based on the Magento database structure. I
I am trying to create forms where the user can input text in up
I'm trying to create table from view from remote server (calling procedure UPDATE_PROC), like
I am trying to create this table in a MySQL database CREATE TABLE IF
Hi this is the table I am trying to create: CREATE TABLE images (
I am trying to create a table for printing purpose. As seen in many

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.