HTML Forms
HTML Forms
HTML Forms
<input type="button">
• The <input type="button"> defines a clickable
button.
• To make buttons do anything, you have to
write JavaScript code to do the work.
• <input type="button" value="Click Me">
• If you don't specify a value, you get an empty
button.
<form>
<input type="button" value="Start machine">
</form>
<p>The machine is stopped.</p>
<script>
const button = document.querySelector('input');
const paragraph = document.querySelector('p');
button.addEventListener('click', updateButton);
function updateButton() {
if (button.value === 'Start machine') {
button.value = 'Stop machine';
paragraph.textContent = 'The machine has started!';
} else {
button.value = 'Start machine';
paragraph.textContent = 'The machine is stopped.';
}
}
</script>
<input type="password">
• <input> elements of type password provide a
way for the user to securely enter a password.
• The element is presented as a one-line plain
text editor control in which the text is
obscured so that it cannot be read, usually by
replacing each character with a symbol such as
the asterisk ("*") or a dot ("•").
<label for="userPassword">Password: </label>
<input id="userPassword" type="password">
<input type="submit">
• <input> elements of type submit are rendered
as buttons. When the click event occurs, the
user agent attempts to submit the form to the
server.
– <input type="submit" value="Send Request">
<input type="email">
• <input> elements of type email are used to let the
user enter and edit an e-mail address, or, if the
multiple attribute is specified, a list of e-mail
addresses.
– <input id="emailAddress" type="email">
<input type="date">
• <input> elements of type="date" create input fields
that let the user enter a date, either with a textbox
that validates the input or a special date picker
interface.
<form action="https://example.com">
<label>
Enter your birthday:
<input type="date" name="bday">
</label>
<p><button>Submit</button></p>
</form>
This HTML submits the entered date under the key bday to
https://example.com — resulting in a URL like
https://example.com/?bday=1955-06-08