Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

form data display javascript

// Form Details display in plain JAVASCRIPT
// HTML
  <body>
    <form action="#">
      <input
        type="text"
        id="myName"
        placeholder="enter your name"
      /><br /><br />
      <input
        type="text"
        id="myNumber"
        placeholder="enter your Number"
      /><br /><br />
    </form>
    <input type="submit" onclick="buttonSubmit()" />
    <table id="user-table">
      <thead>
        <tr>
          <th>Name</th>
          <th>Age</th>
        </tr>
      </thead>

      <tbody id="user-table-data"></tbody>
    </table>
  </body>

// javascript
  <script>
    let userList = [];
    const buttonSubmit = () => {
      let nameInput = document.getElementById("myName").value;
      let numberInput = document.getElementById("myNumber").value;
      let myData = {
        name: nameInput,
        number: numberInput,
      };
      userList.push(myData);
      localStorage.setItem("userData", JSON.stringify(userList));
      tableDataPopulate();
    };
    const tableDataPopulate = () => {
      const allData = localStorage.getItem("userData");
      const table = document.getElementById("user-table-data");
      let userHtml = "";
      userList.forEach((user, i) => {
        userHtml += `<tr><td>${user.name}</td><td>${user.number}</td></tr>`;
      });
      table.innerHTML = userHtml;
    };
  </script>
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript compare number 
Javascript :: jquery select direct child 
Javascript :: d3 v6 
Javascript :: create shadow root 
Javascript :: max value javascript 
Javascript :: how to add two floats 
Javascript :: jest test navlink 
Javascript :: javascript get currency symbol by currencyCode 
Javascript :: concat 
Javascript :: jsx return greatest number between two numbers 
Javascript :: create method javascript 
Javascript :: events onclick 
Javascript :: mongodb findoneandupdate return new document 
Javascript :: private route in react js 
Javascript :: prisma bigint 
Javascript :: javascript function add two numbers 
Javascript :: bresenham algorithm 
Javascript :: search with multiple field in node js mongodb 
Javascript :: flatlist inside flatlist react native 
Javascript :: addAndRemoveClassJquery 
Javascript :: datatable dropdown toggle not working 
Javascript :: mongoose find in array 
Javascript :: nodejs class template export 
Javascript :: check if alpine js is activated in website 
Javascript :: how to add a message sound in angular 
Javascript :: async await 
Javascript :: how to convert string to toggle case in javascript 
Javascript :: angular 8 remove cookies 
Javascript :: mongoose search multiple fields 
Javascript :: change view port of svg with javascript 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =