Category: Vanilla Javascript

Added: 15th of October 2018

Updated On: 24th of October 2020

Viewed: 1683 times

Using document.getElementById() in javascript to send form data

This article was rechecked and updated on 24/10/20

The code below takes the form input and displays the result by using the document.write() comment.

Example 2: Using document.write() command in Javascript
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">

function 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.

Other Tips & Tutorials

Vanilla Javascript

Display date and time using Javascript

Posted: 25th of July 2021

Views: 235

Vanilla Javascript

Clear all form fields using Javascript

Posted: 25th of October 2020

Views: 1084

Vanilla Javascript

Generate a random number between 1 and 5 using Math.floor and Math.random commands in Javascript

Posted: 22nd of October 2018

Views: 1839

Vanilla Javascript

Using document.getElementByID() in javascript to send form data

Posted: 15th of October 2018

Views: 1683

Vanilla Javascript

Using document write() in javascript.

Posted: 14th of October 2018

Views: 2028