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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:41:13+00:00 2026-05-30T14:41:13+00:00

I’m learning Javascript for a project. I’m trying to try and get values from

  • 0

I’m learning Javascript for a project. I’m trying to try and get values from an dynamic number of text inputs into a multi-dimensional array. I have tried this with 1 text field and it correctly saves into the array for further manipulation later. However when i added an second text field and another dimension to the array, it broke. Eventually i will have a drop down list to give the number of inputs once i figure it out. Here’s my current code, not very efficient really.

    <html>
<head>
    <title> JavaScript Array from Input</title>
    <script>

        var array = new Array();

        function insert(val){
            array[0][array.length]=val;
        }

         function insert2(val){
            array[array.length][0]=val;
        }

        function show() {
            var string="<b>All Element of the Array :</b><br>";
            for(i = 0; i < array.length; i++) {
                string =string+array[i][0]+"<br>";
                string =string+array[0][i]+"<br>";
            }
            if(array.length > 0)
                document.getElementById('myDiv').innerHTML = string;
        }
    </script>

</head>

<body>
    <h2>JavaScript Array from Input</h2>
    <form name="form1">
        <table width="407">
            <tr>
                <td width="154" align="right"><b>Name</b>
                <td width="9"><b>&nbsp;:</b>
                <td width="224">
                <input type="integer" name="name"/>
            </tr>
            <tr>
                <td width="154" align="right">
                <td width="9">
                <td width="224">
            </tr>
            <tr>
                <td width="154" align="right">
                <td width="9">
                <td width="224">


                <td width="154" align="right"><b>Name2</b>
                <td width="9"><b>&nbsp;:</b>
                <td width="224">
                <input type="integer" name="name2"/>
            </tr>
            <tr>
                <td width="154" align="right">
                <td width="9">
                <td width="224">
            </tr>
            <tr>
                <td width="154" align="right">
                <td width="9">
                <td width="224">
                <input type="button" Value="Add Into Array" 
                       onclick="insert(this.form.name.value), insert2(this.form.name2.value);"/>

                                        <input type="button" Value="alert" 
                       onclick="alert(array[0][0])"/>
            </tr>
        </table>

    </form>
    <div id="myDiv"></div>
</body>

  • 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-30T14:41:14+00:00Added an answer on May 30, 2026 at 2:41 pm

    In case you didn’t figured it out yet here is the code:

    <html>
    

    <script>
        var arrayX =5;
        var arrayY =2;
        var array=new Array(arrayX);
        var arrayIndex=0;
    
    
        for (x=0; x<array.length; x++)
        {
            array [x] = new Array(arrayY);            
        }
    
        function insert(val1, val2){
        if (arrayIndex >= arrayX)
        {
        alert("End of array!");
        return false;
        }
    
            array[arrayIndex][0]=val1;
            array[arrayIndex][1]=val2;
            arrayIndex++;
            document.getElementById('name1').value = '';
            document.getElementById('name2').value = '';
        }
    
        function show() {
            var string='<b>All Element of the Array :</b><br>';
            for(i = 0; i < array.length; i++)
            {
            string+='array['+i+']:'+array[i][0]+'-'+array[i][1]+'<br>';
            }
            if(array.length > 0)
            document.getElementById('myDiv').innerHTML = string;
        }
    </script>
    
    </head>
    <body>
        <h2>JavaScript Array from Input</h2>
        <form name="form1">
            <table width="407">
                <tr>
                    <td width="154" align="right"><b>Name1</b></td>
                    <td width="9"><b>&nbsp;:</b></td>
                    <td width="224">
                    <input type="integer" name="name" id="name1"/></td>
                </tr>
                <tr>
                    <td width="154" align="right"><b>Name2</b></td>
                    <td width="9"><b>&nbsp;:</b></td>
                    <td width="224">
                    <input type="integer" name="name2" id="name2"/></td>
                </tr>
    
    
            </table>
            <table width="407">
            <tr>
            <td><input type="button" value="Add Into Array"
                           onclick="insert(this.form.name.value,this.form.name2.value);"/>
    </td>
    <td>
                    <input type="button" value="alert"
                           onclick="show();"/>
    </td>
    </table>
    </form>
    <div id="myDiv"></div>
    
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am currently running into a problem where an element is coming back from
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to render a haml file in a javascript response like so:
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has

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.