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

  • Home
  • SEARCH
  • 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 8304883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:57:26+00:00 2026-06-08T17:57:26+00:00

I am trying to create a table that is generated by user input data.

  • 0

I am trying to create a table that is generated by user input data.

The table is reflecting a grid therfore I want the id of each cell to be the co ordinate of that grid. So the id of the bottom left cell would be id00. The top right cell id would be the maximum size of the grid that the user has entered.

So for example if data entered; x value=3; y value=3
this would produce the following table:

<table>
<tr><td id="id03"></td><td id="id13"></td><td id="id23"></td><td id="id33"></td></tr>
<tr><td id="id02"></td><td id="id12"></td><td id="id22"></td><td id="id32"></td></tr>    
<tr><td id="id01"></td><td id="id11"></td><td id="id21"></td><td id="id31"></td></tr>
<tr><td id="id00"></td><td id="id10"></td><td id="id20"></td><td id="id30"></td></tr>
</table>

I have identified the basic concept for the code as you can see below:

<table>
Create a loop,  initial value of r= 0; maximum value of r=y
r =0 <tr> create a secondary  loop, initial value of n=0; maximum value of n = x;  r remains  constant for row
n=0; r= 0 <td  id = “id” + “[x- (x-n)]” +   “[y-r]” > </td>
….
n=3; r= 0* <td id = “id” + “[x- (x-n)]” +   “[y-r]” > </td>
</tr>

….

r =3 <tr> n=0; r= 3 <td  id = “id” + “[x- (x-n)]” +   “[y-r]” > </td>
….
n=3; r= 3<td id = “id” + “[x- (x-n)]” +   “[y-r]” > </td>
</tr>
</table>

I want to develop it in Javascript but I am new to the language and I am having trouble coding it.

Any help anyone could provide would be greatly appreciated.

  • 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-08T17:57:27+00:00Added an answer on June 8, 2026 at 5:57 pm

    Try something like this :

    var rows = parseInt(document.getElementById('rows').value,10); // get input value
    var cols = parseInt(document.getElementById('cols').value,10); // get input value
    var table = document.createElement('table'); // create table element
    table.border = "1"; // set some attributes
    var prevrow; // used to store previous row element
    for (var r = 0; r < (rows+1); r++) {  // loop rows
        var row = document.createElement('tr'); // create tr
        for (var c = 0; c < (cols+1); c++) { // loop cols
            var col = document.createElement('td'); // create td
            col.id = 'id' + r + c;  // set id of tr
            col.innerHTML = col.id; // add some text
            row.appendChild(col); // append td to tr
        }
        // if first tr then create append to table else insert before previous tr
        if (prevrow) {
            table.insertBefore(row, prevrow);
        } else {
            table.appendChild(row);
        }
        // store newly create tr
        prevrow = row;
    }
    // append the new table to the output div
    document.getElementById('output').appendChild(table);
    

    Uses document.createElement(), element.appendChild() and element.insertBefore() to build the table

    Working example here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data.frame and I'm trying to create a frequency table that shows
I am trying to create a table with values that are in a String
I am trying to figure out how to create a temporary table that is
I'm trying to translate a table RoomType. I create a Texts table that contains:
I am trying to create a template that will put items in a table.
Im trying to create an ajax (post) event that will populate a table in
I'm trying to create a <table> that doesn't exceed a certain width (let's say
I am trying to create a report that pulls data from 2 tables: a
I'm trying to create a quick and dirty simple menu that is generated by
I have an application that sends data based on user interaction (not user input).

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.