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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:08:32+00:00 2026-06-18T14:08:32+00:00

I’ve developed some javascript which generates a dynamic table from an array, then allows

  • 0

I’ve developed some javascript which generates a dynamic table from an array, then allows the user to edit the data. This works perfect.

Now I want to do use this code 3 times on the same HTML page. At the moment it depends on two variables: metadata, which describes the header format and is read only and the same for all three occasions, and ‘data’ which actually holds the data for the table.

Rather than having three copies of the code for each instance, I’m thinking it would be better to have an object which keeps everything internal and simply has ‘setData’ and ‘getData’ methods.

Existing code dynamically creates onclick events – how to get these to reference the objects function, rather than a global function? (ie, there is currently functions like ‘RemoveRow(index)’, which I assume will be ‘obj.RemoveRow(index)’. I would love to do this in jquery but alas, I wouldn’t know the rowindex to pass in then, unless someone has a solution. Perhaps store it somewhere inside the DOM and access it somehow to determine the row being clicked on?

Is it possible to pass a reference to an array? It would be much better if the object could manipulate the array passed in rather than making a copy to work on and then the caller having to copy that back to its own array.

  • 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-18T14:08:33+00:00Added an answer on June 18, 2026 at 2:08 pm

    So this is very raw code and only one of multiple options, but maybe you get the idea:

    Create an object that handles a single table

    function TableControl () {
        // dom elements
        this.table = null;
        this.rows = null;
        // values
        this.id = null;
        // create new row
        this.insertRow = function() {
            // some logic
            this.table.append( 'new row goes here' );
        },
        // load table object and rows and stuff
        this._initiate = function() {
            //create object with all passed arguments
            var args = arguments[0] || {};
    
            // set internal values
            this.id = args.id;
    
            // get dom elements
            this.table = $('#' + this.id);
            this.rows = this.table.find('tr');
        },
        this._initiate( arguments[0] );
    }
    

    Create instances of that object using the id of each table

    var table_1 = new TableConrol({ id: 'table_1' });
    var table_2 = new TableConrol({ id: 'table_2' });
    var table_3 = new TableConrol({ id: 'table_3' });
    

    So each table handles only stuff within it’s own “scope”, like adding new rows for example:

    table_1.insertRow();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from
I am using jsonparser to parse data and images obtained from json response. When
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am confused How to use looping for Json response Array in another Array.
I am trying to understand how to use SyndicationItem to display feed which is
I have a small JavaScript validation script that validates inputs based on Regex. I

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.