Persisting dynamically generated table information into a multidimensional array

I've created a dynamic table and now I'm trying to extract the data from it and store it in a multidimensional array. However, I keep encountering an exception/error that says "Cannot set property of 0 to undefined". https://i.sstatic.net/W8B9j.png

Here's my JS Function:

var DefAttrArray = new Array(100);

    function storeDefinedStreamInfo(newAgent,i,e,ui)
    {
        var StrName= document.getElementById("StreamNameInput").value;
        var StreamElementID = i;
        var table = document.getElementById('attrtable');
        var tblerows = (table.rows.length)-1;

        for (r = 1; r < table.rows.length; r++) {
            for(var c=0; c<1;c++) {
                var attrNm = table.rows[r].cells[c].innerHTML;
                var attrTp = table.rows[r].cells[1].innerHTML;
                createdDefinedStreamArray[i-1][2][r-1]= new Array(2);
                createdDefinedStreamArray[i-1][2][r-1][0]=attrNm;
                createdDefinedStreamArray[i-1][2][r-1][1]=attrTp;
                alert(createdDefinedStreamArray[i-1][2][r-1][0] + "\n" + createdDefinedStreamArray[i-1][2][r-1][1]);
            }

        }

        createdDefinedStreamArray[i-1][0]=StreamElementID;
        createdDefinedStreamArray[i-1][1]=StrName;
        createdDefinedStreamArray[i-1][2]=new Array(tblerows);
        createdDefinedStreamArray[i-1][3]="Defined Stream";

        alert("createdDefinedStreamArray[i-1][2][w][0] : "+ createdDefinedStreamArray[i-1][2][w][0]);

        var prop = $('<a class="streamproperty" onclick="doclickExp(this)"><b><img src="../Images/settings.png"></b></a> ').attr('id', (i));
        var showIcon = $('<img src="../Images/Defined.png"></b></a> ').attr('id', (i));
        newAgent.text(StrName).append('<a class="boxclose" id="boxclose"><b><img src="../Images/Cancel.png"></b></a> ').append(showIcon).append(prop);
        dropCompleteElement(newAgent,e,ui);
    }

Answer №1

Finally, success!

let defaultAttributes = new Array(100);

function saveStreamInfo(newAgent, i, e, ui) {
    let streamName = document.getElementById("StreamNameInput").value;
    let streamElementID = i;
    let table = document.getElementById('attrtable');
    let numRows = (table.rows.length) - 1;
    createdDefinedStreamArray[i][2] = new Array(numRows);

    for (let r = 1; r < table.rows.length; r++) {
        for (let c = 0; c < 1; c++) {
            let attrName = table.rows[r].cells[c].innerHTML;
            let attrType = table.rows[r].cells[1].innerHTML;
            createdDefinedStreamArray[i][2][r - 1] = new Array(2);
            createdDefinedStreamArray[i][2][r - 1][0] = attrName;
            createdDefinedStreamArray[i][2][r - 1][1] = attrType;
        }
    }

    createdDefinedStreamArray[i][0] = streamElementID;
    createdDefinedStreamArray[i][1] = streamName;
    createdDefinedStreamArray[i][3] = "Defined Stream";
    createdDefinedStreamArray[i][4] = numRows;

    let property = $('<a class="streamproperty" onclick="doclickDefine(this)"><b><img src="../Images/settings.png"></b></a>').attr('id', i);
    let icon = $('<img src="../Images/Defined.png"></b></a>').attr('id', i);
    newAgent.text(streamName).append('<a class="boxclose" id="boxclose"><b><img src="../Images/Cancel.png"></b></a>').append(icon).append(property);
    dropCompleteElement(newAgent, e, ui);
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When dynamically adding input fields in Bootstrap, there is a smaller gap between inline inputs

When adding a new list item dynamically in a modal using jQuery append, the spacing in the first li element seems to have a larger gap between the input fields compared to the rest that are added later. Even after checking the developer tools and confirmin ...

What is the reason behind the inconsistent behavior of Javascript's Date.getDate() and .setDate() methods?

As a hobbyist coder, I'm facing a challenging problem with building a dynamic HTML/CSS calendar. My goal is to have cells filled in based on today's date. However, when I attempt to add days to fill in another 13 days by looping through HTML elem ...

Using the shift() method in Javascript to manipulate Objects

My goal is to take my list and combine the first two items (0 & 1) together. I attempted the following code: total=foo.shift(); foo[0]=total However, I encountered this error: Uncaught TypeError: Object [object Array] has no method &ap ...

Preventing event propagation in jQuery's click handler

Is it possible to prevent the propagation of a click event on a dynamically created div within its parent div? HTML <div id = "parent"> Some Stuff </div> Jquery $('#parent').click(function(){ $(this).append('<div class = ...

Can one extract a property from an object and assign it to a property on the constructor?

Currently working with TypeScript, I am looking to destructure properties from an object. The challenge lies in the fact that I need to assign it to a property on the constructor of the class: var someData = [{title: 'some title', desc: 'so ...

Tips for avoiding identical selections in multiple drop-down menus within a table and sending the data to the server via a POST request

For instance: visualizing a chart of infants, where each row the user chooses baby GenderDropDown, then picks a name. It's crucial to prevent duplicate name selections throughout the chart. If a user selects Male & John, that choice should not be ...

JSX Script issue: the input prompt is missing

Greetings! I am currently working on a script to export JSON files from Adobe Illustrator. // Custom function for exporting prefixed objects function exportPrefixedObjects(doc) { // User input for prefixes and reference points var prefixInput = prompt( ...

What is the optimal method for assigning a value to a specific key within a JavaScript JSON object?

Below is the information stored in a file called "fokontanys.json": { "vzdveg643": { "lldistrict":"Ambilobe", "id_province": 7, "id": null }, "vzvsdv5327": { "lldistrict ...

Exploring the depths of nested object arrays

I'm really struggling to complete a FullStackOpen exercise that requires rendering data to the page. With the following code, I need to display the number of Parts each Course has and also reduce the number of Exercises/Parts to show the total exercis ...

The Stepper StepIconComponent prop in MUI is experiencing issues when trying to render styles from the styles object, leading to crashes in the app

Struggling to find a way to apply the styles for the stepper component without using inline styles. I attempted to replicate Material UI's demo, but encountered an error. The code from Material UI's demo that I want to mimic is shown below: http ...

An error occurred when attempting to search for 'length' using the 'in' operator in the context of the Datatables plugin and jQuery 1.11.3

I implemented the jQuery Datatables plugin in my tables for pagination, sorting, and searching functionalities. However, I am facing issues where the elements are not working properly, and the pagination occasionally fails to display. The Chrome console is ...

Adjusting the navigation image as it passes through various div elements during scrolling

Is it possible to dynamically change an image in the navigation bar based on the user's scroll position? For example, I want pic1 to be displayed when the page content is at the top, then switch to pic2 once the user reaches the footer, and then back ...

When a new ajax function is added, the original Ajax code stops functioning

I've been working on getting the code below to function properly. It seems that when I test the code, two validation functions are working correctly. However, when I include the validateUsername() function along with the if statement in the code, ever ...

Exploring the @HostBinding argument in Angular directives

Need help grasping the concept behind the @Hostbinding argument: Snippet of the code: import { Directive, HostBinding } from "@angular/core"; @Directive({ selector: '[appDropdown]' }) export class DropdownDirective { @HostBinding(&apos ...

Determine if the webpage is the sole tab open in the current window

How can I determine if the current web page tab is the only one open in the window? Despite searching on Google for about 20 minutes, I couldn't find any relevant information. I would like to achieve this without relying on add-ons or plugins, but if ...

How can you fetch data from a PHP file using AJAX before performing a header redirect?

I am currently in the process of adding more dynamism to my website. I have developed a forum from scratch and now I am integrating JavaScript into it. All the PHP backend work is complete. My next goal is to enable user login without having to refresh the ...

Transformation of CSS classes in React with Webpack

Have you ever noticed that when you inspect the Airbnb website, the classnames appear to be morphed into single alphanumeric names? What is the name of this technique and is it applied at the code level or build level? https://i.sstatic.net/qSiaj.jpg ...

Having some trouble implementing the functionality of hiding a data series in HighCharts using `{ data: [], visible: false }` notation

I am currently working on creating a graph that displays multiple series obtained from JSON data in a MySQL database. My goal is to have the graph show only one series initially. Thankfully, HighCharts offers an option to achieve this as demonstrated below ...

Generating XML format from JSON using JavaScript

I am looking to create an XML format based on my JSON data, rather than converting it from JSON to XML. Here is an example of the JSON I want to convert to XML: var jsonData = { "Smart Shoes":{ "Product":"Smart Shoes", "Price":24.99, ...

Retrieve the text content of a datalist option by accessing the label with jQuery

Utilizing data from a Json, I am populating a data-list in html. The options are added to the data-list with both value and label text. Upon clicking an option, I aim to insert both the value and text into a form text field. While accessing the option&apo ...