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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:53:45+00:00 2026-05-16T11:53:45+00:00

I am trying to display a table with data in runtime using script. I

  • 0

I am trying to display a table with data in runtime using script.
I called the script from table header. Is that possible to call a function from table header.

</HEAD> 
<BODY> 
<TABLE id="dataTable" width="350px" border="1" onload="start('dataTable');"> 
<TR> 
<THEAD>
<TR>
<TH>Select</TH> 
<TH>Id</TH> 
<TH>Name</TH>
<TH>Age</TH>
<TH>Dept</TH>
<TH>Option</TH> 
</TR> 
    </THEAD>

    </TABLE> 

</BODY> 
</HTML>

The Script is

    function start(dataTable) {
            var data = new Array();
        var id;
        var name;
        var age;
        var dept;
        data[0].id = "1";
        data[0].name = "Tamil";
        data[0].age = "23";
        data[0].dept = "CSE";
        data[1].id = "1";
        data[1].name = "Tamil";
        data[1].age = "23";
        data[1].dept = "CSE";
        data[2].id = "1";
        data[2].name = "Tamil";
        data[2].age = "23";
        data[2].dept = "CSE";


        for (var i = 0; i<data.length; i++)
            {
            var table = document.getElementById(tableID);
            var rowCount = data.length;
            var row = table.insertRow(rowCount);

        //Check box
            var cell1 = row.insertCell(0);
            var element1 = document.createElement("input");
            element1.type = "checkbox";
            cell1.appendChild(element1);
        //ID Column
            var cell2 = row.insertCell(2);
            cell2.innerText = data[i].id;
        //Name Column
            var cell3 = row.insertCell(3);
            cell3.innerText = data[i].name;
        //Age Column    
            var cell4 = row.insertCell(4);
            cell3.innerText = data[i].age;
        //Dept Column
            var cell5 = row.insertCell(5);
            cell5.innerText = data[i].dept;
        //Button Column
            var cell6 = row.insertCell(6);
            var element2 = document.createElement("input");
            element2.setAttribute("type", "button");
            element2.setAttribute("id", "dataRow"+id);
            element2.setAttribute("value", "Edit");
            cell6.appendChild("element2");
            }
      }

The output is just the Headers. I cant get the data into table.

Thanks for suggestions in advance.

  • 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-05-16T11:53:46+00:00Added an answer on May 16, 2026 at 11:53 am

    width=”350px”

    px is CSS. No px when using the HTML attribute.

    onload=”start(‘dataTable’);”

    There is no load event on <table>, this will never be called. Put a <script> element after the table to call the function.

    var data = new Array();

    For sanity, use [] array literal syntax:

    var data= [
        {id: 1, name: 'Tamil', age: 23, dept: 'CSE'},
        ...
    ];
    

    var id; [and name etc.]

    You never use these variables. Declaring vars has nothing to do with members of an object.

    document.getElementById(tableID)

    You called that variable dataTable not tableID.

    cell2.innerText = data[i].id;

    innerText is a non-standard IE extension. Consider using the standard textContent property first, if available, or just use plain old cell2.appendChild(document.createTextNode(data[i].id));, which is supported more widely than either.

    element2.setAttribute(“type”, “button”);

    Never use getAttribute/setAttribute in an HTML document, there are bugs in it in IE. Instead use the DOM Level 2 HTML properties, which are easier to read anyway. element2.type= 'button';.

    cell6.appendChild(“element2”);

    That’s a string, not the variable element2.

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

Sidebar

Ask A Question

Stats

  • Questions 535k
  • Answers 535k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Question is not that much DDD related. It's about performance.… May 17, 2026 at 1:08 am
  • Editorial Team
    Editorial Team added an answer The SWF you are loading probably has the channel set… May 17, 2026 at 1:08 am
  • Editorial Team
    Editorial Team added an answer One thing is to use the ConditionalAttribute: [Conditional("DEBUG")] public void… May 17, 2026 at 1:08 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Made solution change: I am trying to display a html table of data.. In
I'm trying to generate a dynamic table using CSS: <html> <head> <style> div.el1, div.el2
Here is my current code. I'm trying to display data from three separate queries
I am trying to grab the data from the database and display all the
I am basically trying to retrieve some data from a MySql server, and display
I am trying to display a default value (or even NO value) when selected
My scenario is as follows: I have a table of data (handful of fields,
I am trying to display a SpreadSheet in the Android application with auot adjustable
I could use some help writing a SQL query. I'm trying to display some
I have code: <display:table name=sessionScope.allUserslist id=userList export=false pagesize=1> <display:column title=Select style=width: 90px;> <input type=checkbox

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.