Source Code:
(back to article)
Submit
Result:
Report an issue
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Input Value Example</title> </head> <body> <form name="userForm"> <input type="text" name="firstName" placeholder="First Name"> <input type="text" name="lastName" placeholder="Last Name"> <input type="submit" value="Submit"> </form> <div id="welcomeMessage"></div> <script> var form = document.forms['userForm']; var firstName = form.elements['firstName']; var lastName = form.elements['lastName']; firstName.value = 'John'; lastName.value = 'Doe'; form.onsubmit = function() { var welcomeMessage = document.getElementById('welcomeMessage'); welcomeMessage.textContent = 'Hello, ' + firstName.value + ' ' + lastName.value + '!'; return false; // Prevents the form from submitting to a server } </script> </body> </html>