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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:06:26+00:00 2026-06-18T09:06:26+00:00

I want to create table using javascript and fill it with data. So I

  • 0

I want to create table using javascript and fill it with data. So I decided to use prompt method and loop while.

But when I try to load page I always get two error message in google chrome developer tools
enter image description here

Here is the code

<html>
<head>
    <meta charset="utf-8">
    <script type="text/javascript">
    function onStart() {
        var list = new Array();
        var headers = new Array("Имя","Отчество","Фамилия","Дата рождения");
        var i = -1;
        while(true) {
            var a = prompt("Имя","noname");
            var b = prompt("Отчество","nomiddlename");
            var c = prompt("Фамилия","nosurname");
            var d = prompt("Дата рождения!",0);
            if (confirm("Уверены что хотите добавить студента?")) {
                i++;
                list[i] = a + "-" + b + "-" + c + "-" + d;
            }else{ break; };
        }
        tab = "<table>";
        for(j = 0; j<headers.length;j++) {
            tab += "<th>" + headers[j] + "</th>";
        for(var j = 0; j < list.length; j++) {
            var params = list[i].split('-');
            tab += "<tr>";
            for(k = 0; k < params.length;k++) {
                tab +="<td>" + params[k] + "</td>";
            }
            tab +="</tr>";
        }
        tab +="</table>";
        document.write(tab);
    };
    </script>
</head>
<body onLoad = "onStart()">
</body>

What’s the problem?

  • 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-18T09:06:27+00:00Added an answer on June 18, 2026 at 9:06 am

    Your for loops seem to be mis-indented and not closed properly

    for(j = 0; j<headers.length;j++) {
            tab += "<th>" + headers[j] + "</th>";
        for(var j = 0; j < list.length; j++) {
            var params = list[i].split('-');
            tab += "<tr>";
            for(k = 0; k < params.length;k++) {
                tab +="<td>" + params[k] + "</td>";
            }
            tab +="</tr>";
        }
    

    Should be

    for(j = 0; j<headers.length;j++) {
        tab += "<th>" + headers[j] + "</th>";
    }
    for(var j = 0; j < list.length; j++) {
        var params = list[i].split('-');
        tab += "<tr>";
        for(k = 0; k < params.length;k++) {
            tab +="<td>" + params[k] + "</td>";
        }
        tab +="</tr>";
    }
    

    Not directly related to your question, but you have a few other common javascript errors.
    By not declaring variables with var, you are unintentionally creating global variables. While this probably isn’t a huge issue on your page, but it is bad practice.

    In addition, you should wrap your <th> tags you are appending inside of a <tr>, as the only “valid” element within a <table> is a <tr> (technically its tbody, thead, and tfoot, of which the only valid children is <tr>).

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

Sidebar

Related Questions

I totally want to avoid using inline javascript! But i have a table which
I'm using multi-table-inheritance , and want to know how to create an inherited type
I want to create some table through PHP but it fails everytime, but the
I want to create a table with String keyvalues and integer data. Right now
In page_load, I create a table and fill it with data gathered from a
I'm using JavaScript to dynamically add rows to a table, I create some textboxes
How to create a Html table using DOM model using Javascript? for ex: <table
I am using below javaScript code to create table in runtime. And i somewhat
Possible Duplicate: Custom alert using Javascript I want to create a confirmation message-Do you
i know how to post data using javascript but im trying to work out

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.