HTML - Forms Input - Set 2
HTML forms are used to collect and submit user input. They allow users to enter data, make selections, and interact with a web page. Let's explore the components and attributes of HTML forms in detail:
Checkbox Input (<input type="checkbox">):
Meaning: Checkboxes allow users to select multiple options from a set of choices.
Usage: Use the <input type="checkbox"> tag to create checkbox inputs. Each checkbox must have a unique name attribute and a corresponding value attribute.
<form>
<input type="checkbox" id="option1" name="options" value="option1">
<label for="option1">Option 1</label><br>
<input type="checkbox" id="option2" name="options" value="option2">
<label for="option2">Option 2</label><br>
<input type="checkbox" id="option3" name="options" value="option3">
<label for="option3">Option 3</label><br>
</form>
Button Input (<input type="button">):
Meaning: Button inputs are used to trigger specific actions when clicked.
Usage: Use the <input type="button"> tag to create a button input.
<form>
<!-- Form fields go here -->
<input type="button" value="Click Me" onclick="alert('Button clicked!')">
</form>
File Input (<input type="file">):
Meaning: File inputs allow users to select files from their device.
Usage: Use the <input type="file"> tag to create a file input field.
<form>
<input type="file" id="file" name="file">
</form>
Image Input (<input type="image">):
Meaning: Image inputs allow users to submit a form by clicking on an image.
Usage: Use the <input type="image"> tag to create an image input. The src attribute specifies the image URL.
<form>
<input type="image" src="image.jpg" alt="Submit">
</form>
These are examples of HTML form input tags that provide various functionalities for collecting user input. Remember to include the necessary attributes and use appropriate JavaScript or server-side code to handle the form submission and processing.