This article was updated and rechecked on 24th of October 2020
Added: 15th of October 2018
Updated On: 24th of October 2020
Viewed: 2,797 times
The code below takes the form input and displays the result by using the document.write() comment.
Create a new .html document on your desktop, and rename the file example2.html
Open the document in your text editor and copy and paste the following code.
<form method="post" action="#" onSubmit="submit_form();">
First Name: <input type="text" name="first_name" id="fn" value=""
<input type="submit" name="submit" value="Submit Form">
var first_name = document.getElementById('fn').value;
document.write("Hello ", first_name);
Save the document and open it in your web browser. The form will take user input, and print the result on the next page.