Buy best selling Linux books

<< View More Computer Tips

Added On: 15/10/18   |    Category: Vanilla Javascript    |    Number of Views: 511

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

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 webbrowser. My Computer Tips will be printed to the screen.

Example 1: Using document write() in javascript
Example 2: Using document.getElementByID() in javascript to send form data
Example 3: Generate a random number between 1 and 5 using Math.floor and Math.random commands in Javascript

Search Site

Search other tutorials and tips on My Computer Tips by entering your search terms below


The Linux Foundation

Best selling Unix / Linux books
Nvidia Graphics Cards
Save 15% off .CO.UK domains at 123-Reg
Save 15% off .COM domains at 123-Reg
cPanel Hosting Plans
Xilo Web Hosting Plans