Store and display the values of text boxes of a form

 <!DOCTYPE html>

<html>

<head>
  <meta charset=utf-8 />
  <title>Return first and last name from a form - w3resource</title>
</head>

<body>
  <div id="content"></div>
  <form id="form1" onsubmit="getFormvalue()">
    First name: <input type="text" name="fname" value="David" id="fname"><br>
    Last name: <input type="text" name="lname" value="Beckham" id="lname"><br>
    <input type="submit" value="Submit">
  </form>

  <script>
    function getFormvalue() {
      let fname = document.getElementById("fname");
      let lname = document.getElementById("lname");
      let content = document.getElementById("content");

      let fnamev = fname.value;
      let lnamev = lname.value;

      alert(fnamev + " " + lnamev);
    }
  </script>
</body>

</html>

Comments

Popular posts from this blog

Write a JavaScript program to get the current date.

Write a JavaScript program to count and display the items of a dropdown list, in an alert window