Display or Get Input Value in JavaScript

In JavaScript, you can use the value property of an input element to get or set the value of the element. For example, given an input element with the ID, you can get the value of the element with the following code:

JavaScript

<script type="text/javascript">
function databio() {
 var name= document.getElementById("name").value;
 var email= document.getElementById("email").value; 
  document.writeln("Hi, my name is " +name+ "<br>");
  document.writeln("You can contact via email: " +email+  "<br>");
}
</script>

Form

<form onsubmit="databio()">
Enter Name: <input type="text" placeholder="Enter your name."  id="name" /><br/>
Enter Email: <input type="email" placeholder="Enter the email." id="email" /></><br/>
<input type="submit" value="Submit Now">
</form>

Complete Code:

<!DOCTYPE html>
<html>
<head>
<title>Input Data - Javascript</title>
<script type="text/javascript">
function databio() {
 var name= document.getElementById("name").value;
 var email= document.getElementById("email").value; 
  document.writeln("Hi, my name is " +name+ "<br>");
  document.writeln("You can contact via email: " +email+  "<br>");
}
</script>
</head>

<body>
<form onsubmit="databio()">
Enter Name: <input type="text" placeholder="Enter your name."  id="name" /><br/>
Enter Email: <input type="email" placeholder="Enter the email." id="email" /></><br/>
<input type="submit" value="Submit Now">
</form>
</body>
</html>
Next Post Previous Post
No Comment
Add Comment
comment url