Source Code: (back to article)
<!DOCTYPE html>
<html>
<head>
<title>Selecting Form Elements</title>
</head>
<body>
<h4>Fill the form inputs, and press 'Show Input Values' button.</h4>
<form id="userForm">
<input type="text" id="username" name="username" placeholder="Username">
<input type="email" id="email" name="email" placeholder="Email">
</form>
<button id="showInputs">Show Input Values</button>

<script>
// Select elements by ID
const username = document.getElementById('username');
const email = document.getElementById('email');
const showInputsButton = document.getElementById('showInputs');

showInputsButton.addEventListener('click', () => {
alert(`Username: ${username.value}, Email: ${email.value}`);
});
</script>
</body>
</html>