Using HTML and CSS to capture user input data and store it in an array

I've created a form that allows users to add and remove multiple fields, ranging from one to three.

My goal is to retrieve the form data and store it in an array.

index.html

<!DOCTYPE html>
<html lang="en">
   <head>
      <meta charset="UTF-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Document</title>
      <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="02606d6d76717670637242372c322c30">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
   </head>
   <body>
      <section>
         <div class="container">
            <form method="post" action="submit.php">
               <div class="form-group fieldGroup">
                  <div class="input-group">
                     <div class="row">
                        <div class="col-lg-4">
                           <input type="text" name="userfname" class="form-control" placeholder="Enter First Name"/>
                        </div>
                        <div class="col-lg-4">
                           <input type="text" name="usermname" class="form-control" placeholder="Enter Middle Name"></input></div>
                        <div class="col-lg-4">
                           <input type="text" name="userlname" class="form-control" placeholder="Enter Last Name"></input></div>
                     </div>
                     <div class="row">
                        <div class="col-lg-4">
                           <input type="text" name="usermobilenumber" class="form-control" placeholder="Enter Mobile Number"></input></div>
                        <div class="col-lg-4">
                           <input type="text" name="userdob" class="form-control" placeholder="Enter Date of birth"></input></div>
                        <div class="col-lg-4">
                           <select id="gender">
                              <option value="volvo">Male</option>
                              <option value="saab">Female</option>
                           </select>
                        </div>
                     </div>
                     <div class="row">
                        <div class="col-lg-4">
                           <input type="text" name="useremail" class="form-control" placeholder="Enter Email id.."></input></div>
                        <div class="col-lg-4">
                           <input type="text" name="userpassword" class="form-control" placeholder="password"..></input></div>
                        <div class="col-lg-4">
                           <select id="User Category">
                              <option value="">Head of Family</option>
                              <option value="">Mother</option>
                              <option value="">Father</option>
                              <option value="">Brother</option>
                              <option value="">Sister</option>
                              <option value="">Dependent</option>
                              <option value="">Child</option>
                              <option value="">Spouse</option>
                           </select>
                        </div>
                     </div>
                     <div class="row">
                        <div class="input-group-addon"> 
                           <a href="javascript:void(0)" class="btn btn-success addMore"><span class="glyphicon glyphicon glyphicon-plus" aria-hidden="true"></span> Add</a>
                        </div>
                     </div>
                  </div>
               </div>
               <input type="submit" name="submit" class="btn btn-primary" value="SUBMIT"></input>
            </form>
            <!-- copy of input fields group -->
            <div style="display:none;">Sample code for input fields here </div>
          </div>
       </section>
     <script src="js/index.js"></script>
      <script src="https://cdn.jsdelivr.net/npm/<a href='/cdn-cgi/l/email-protection' class='__cf_email__' data-cfemail='abc9c4c4dfd8dfd9cadbeb9e859b8599'>[email protected]</a>/dist/js/bootstrap.bundle.min.js"></script>
    </body>
  </html>
  

index.js

$(document).ready(function(){
//group add limit
var maxGroup = 15;

//add more fields group
$(".addMore").click(function(){
if($('body').find('.fieldGroup').length < maxGroup){
var fieldHTML = '<div class="form-group fieldGroup">'+$(".fieldGroupCopy").html()+'</div>';
$('body').find('.fieldGroup:last').after(fieldHTML);
}else{
alert('Maximum '+maxGroup+' groups are allowed.');
}
});

 //remove fields group
 $("body").on("click",".remove",function(){ 
        $(this).parents(".fieldGroup").remove();
 });
});

I am aiming to gather all the form values into an array-like structure as shown below:

[{'name': 'InputName', 'email': 'InputEmail'}, {'name': 'InputName', 'email': 'InputEmail'}]
 

I have designed two arrays within JSON format to accommodate my intended data based on the number of forms added.

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

What is the origin of the libraries found in npm-shrinkwrap that do not match the packages listed in package.json?

I'm puzzled by the presence of `express` in my `npm-shrinkwrap` file as a main dependency. Despite this, `express` is not listed as a dependency in my `package.json` file. I can't find any usage of it in my project. It's not included a ...

Removing duplicate data from Table TD and TR elements using Jquery

I am working on an HTML table and I need to remove duplicate values in each <tr> and <td> data cell. Here is a snippet of my code: <table width="100%" id="l2table"> <thead><tr> ...

Access a document from a collaborative directory directly in a web browser

When I paste the shared path for a PDF file into the address bar, it opens perfectly in all browsers. The code below works fine in IE 8 but not in Chrome and Firefox. Code: function openPDF(file) { window.open(file, '_blank'); } function link ...

Is there a way to customize the CSS for a single blog post and add a 5-star rating system without affecting other posts?

After launching my blog on Google's Blogger, I wanted to add a unique touch by incorporating a static 5-star rating system in my Books I Read Section. I thought about using CSS to customize each book post and display anywhere from 1 to 5 stars for vis ...

The JQuery Datepicker function consistently returns a null value when attempting to retrieve the selected date

I've encountered a challenge while working on a project recently. Currently, I'm utilizing Spring 3.0 with its integrated validation alongside Hibernate 3.6. My goal is to implement a JQuery datepicker for users to input dates. However, the dat ...

Strategies for efficiently creating reusable HTML templates for recurring content blocks?

I am just starting out in web development and have encountered a problem with navigating through my page. The layout of the pages is the same, except for a div container. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3 ...

Comparing the impact of class and element selectors on CSS performance

Considering that CSS is read from right to left, I am pondering the balance between performance and readability when it comes to adding classes to HTML in order to more efficiently target elements in CSS. Additionally, I am curious about how using a gener ...

I'm a beginner when it comes to Android WebView and incorporating JavaScript into my projects

Struggling to make my Android app work with JavaScript, even though I've enabled it. Despite all the research I've done suggesting it should work, it's not. Any assistance would be greatly appreciated. Below is my Java code: protected ...

Instructions on adding a class to the parent element when the child has a particular class

Here is the html structure I am working with: <section> <div class="v-middle"> <div class="row"> <h5 class="heading">Heading goes here</h5> </div> </div> </section> ...

Is it possible that React.createElement does not accept objects as valid react children?

I am working on a simple text component: import * as React from 'react' interface IProps { level: 't1' | 't2' | 't3', size: 's' | 'm' | 'l' | 'xl' | 'xxl', sub ...

Issue with the alignment of a sidebar on a website's html page

Last week, I embarked on the journey to learn HTML and CSS. To put my skills to the test, I decided to recreate an old web page using what I have learned so far. The specific page I am trying to emulate can be found here: However, I am currently facing so ...

Attempting to conceal image previews while incorporating pagination in Jquery

I'm working on implementing pagination at the bottom of a gallery page, allowing users to navigate between groups of thumbnail images. On this page, users can click on thumbnails on the left to view corresponding slideshows on the right. HTML <di ...

Ensure that a group of checkboxes is mandatory

I currently have a series of checkboxes set up like so: <label>What is your preferred movie genre?</label> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" id="genre1" name="genre" ...

jQuery Menu shuts down with a .slideToggle load when clicked away from the menu

I have encountered similar questions regarding my menu open/close functionality, which is operated by slideToggle() instead of a class. I prefer not to modify my CSS to make it functional. The requirement is for the menu to close when the user clicks anyw ...

When utilizing AngularJS, a parse error is triggered by array[ {{value}} ], but I prefer to overlook it

Within the controller, I have a selection list that is displayed like this: <select class="input form-control" id="animationTime" ng-options="item as item.label for item in aniCon.timeOptions track by item.id" ng-model="aniCon.popupTime" ...

Exploring MongoDB's Aggregation Framework: Finding the Mean

Is there a way to use the Aggregation Framework in MongoDB to calculate the average price for a specific Model within a given date range? Model var PriceSchema = new Schema({ price: { type: Number, required: true }, date: { ...

What is the process of importing a cascading style sheet into a C# object?

Currently, I am working on a web application and I would like to provide users with the flexibility to change the styling elements of CSS linked to a page through an admin screen. I have been exploring ways to load a CSS file into a C# object or convert ...

The module named "jquery" has not been loaded in this context: _. Please use require() to load it

As I work on migrating my Javascript files to Typescript, I encountered an issue when trying to use the transpiled javascript file in an HTML page. The error message I received is as follows: https://requirejs.org/docs/errors.html#notloaded at makeError (r ...

Sorting WordPress entries by nearby locations

I have WordPress posts that are being displayed on a Google Map. The posts are pulling data from a custom post field that contains the latlng value, where latitude and longitude are combined into one. Additionally, the map shows the user's location u ...

Issue encountered while configuring 'innerHTML' in xmlHttp.onreadystatechange function

Trying to create a JavaScript function that changes the innerHTML of a paragraph within an xmlHttp.onreadystatechange function, I encountered an error in the Chrome Console: Uncaught TypeError: Cannot set property 'innerHTML' of null at XMLH ...