HTML - Forms Explanation with Examples Part-2A

AllJobsInfo

Administrator
Staff member

Attributes​


Certainly! Here are some common attributes that can be used with `<textarea>` elements and `contenteditable` attribute to create multiple-line text input controls in HTML:
`<textarea>` Attributes:
1. **name**: Specifies the name of the input field, which is used to identify the field's value when the form is submitted.
<textarea name="message"></textarea>
2. **rows**: Specifies the visible number of lines in the textarea.
<textarea name="message" rows="4"></textarea>
3. **cols**: Specifies the visible number of characters per line in the textarea.
<textarea name="message" cols="50"></textarea>
4. **maxlength**: Specifies the maximum number of characters that can be entered into the textarea.
<textarea name="message" maxlength="500"></textarea>
5. **placeholder**: Provides a hint to the user about what kind of information is expected in the textarea.
<textarea name="message" placeholder="Enter your message"></textarea>
6. **readonly**: Specifies that the textarea is read-only and cannot be edited by the user.
<textarea name="message" readonly></textarea>
7. **disabled**: Specifies that the textarea is disabled and cannot be interacted with by the user.
<textarea name="message" disabled></textarea>
`contenteditable` Attribute:
1. **contenteditable**: Specifies whether the element's content can be edited by the user. It can be set to "true" or "false".
<div contenteditable="true">Editable content here</div>
2. **style**: Allows you to apply CSS styles to the element to control its appearance and behavior.
<div contenteditable="true" style="width: 300px; height: 100px; border: 1px solid #ccc;">Editable content here</div>
3. **data-* Attributes**: You can also use custom data attributes to store additional information.
<div contenteditable="true" data-custom="value">Editable content here</div>
These attributes can be used to customize the behavior, appearance, and functionality of multiple-line text input controls in HTML.

Select Box Control​

The select box control in HTML, also known as a dropdown menu or dropdown list, allows users to select one option from a list of predefined choices. Here's how you can create a select box control:

<select name="cars" id="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>

Attributes commonly used with select box controls:

1. **name**: Specifies the name of the input field, which is used to identify the selected option when the form is submitted.

2. **id**: Specifies a unique identifier for the select box control, which can be used for associating labels or for JavaScript manipulation.

3. **multiple**: Allows multiple options to be selected from the list. If present, users can select multiple options by holding down the Ctrl (Windows) or Command (Mac) key while clicking.

4. **size**: Specifies the number of visible options in the select box without scrolling. If present, the select box will be rendered as a list box with the specified number of visible options.

5. **disabled**: Specifies that the select box control is disabled and cannot be interacted with by the user.

6. **required**: Specifies that the user must select an option before the form can be submitted.

Each `<option>` element within the `<select>` element represents an option in the dropdown menu. The `value` attribute specifies the value associated with the option, which is what gets submitted to the server when the form is submitted. The text content of the `<option>` element represents the visible label of the option.

Select boxes are commonly used for providing users with a list of options to choose from, such as selecting a country, choosing a category, or picking an item from a list. They offer a compact and intuitive interface for selecting options from a predefined set of choices.

Attributes​

Following is the list of important attributes of <select> tag −
Sr.NoAttribute & Description
1name
Used to give a name to the control which is sent to the server to be recognized and get the value.
2size
This can be used to present a scrolling list box.
3multiple
If set to "multiple" then allows a user to select multiple items from the menu.
Following is the list of important attributes of <option> tag −
Sr.NoAttribute & Description
1value
The value that will be used if an option in the select box box is selected.
2selected
Specifies that this option should be the initially selected value when the page loads.
3label
An alternative way of labeling options

File Upload Box​

The file upload box in HTML allows users to select and upload files from their local device to a web server. Here's how you can create a file upload box:

```html
<input type="file" name="fileToUpload" id="fileToUpload">
```

Attributes commonly used with file upload boxes:

1. **type**: Specifies the type of input field, which is "file" for file upload boxes.

2. **name**: Specifies the name of the input field, which is used to identify the uploaded file when the form is submitted.

3. **id**: Specifies a unique identifier for the input field, which can be used for associating labels or for JavaScript manipulation.

4. **accept**: Specifies the types of files that the file input accepts. It can be a file type or a comma-separated list of file types.

5. **multiple**: Allows users to select multiple files for upload. If present, users can select multiple files by holding down the Ctrl (Windows) or Command (Mac) key while clicking.

6. **required**: Specifies that the user must upload a file before the form can be submitted.

File upload boxes are commonly used in situations where users need to upload files, such as submitting documents, images, or multimedia files. After a file is selected by the user, the file path or file name is displayed next to the upload box. When the form is submitted, the selected file(s) are sent to the server for processing. It's important to note that file uploads typically require server-side processing to handle the uploaded files.

Attributes​

Following is the list of important attributes of file upload box −
Sr.NoAttribute & Description
1name
Used to give a name to the control which is sent to the server to be recognized and get the value.
2accept
Specifies the types of files that the server accepts.

Button Controls​

In HTML, button controls are used to create clickable buttons that perform actions when clicked by the user. There are several types of buttons you can create in HTML. Here are the most commonly used ones:

1. **Submit Button**: Submits the form data to the server.
<button type="submit">Submit</button>

2. **Reset Button**: Resets all form controls to their initial values.
<button type="reset">Reset</button>
3. **Button**: General-purpose button used for custom actions via JavaScript.
<button type="button">Click me</button>
4. **Anchor Button**: Styled anchor tag used as a button. It can be used to navigate to a different page or perform an action.
<a href="https://www.example.com" class="button">Go to Example</a>
Attributes commonly used with button controls:

- **type**: Specifies the type of button. It can be "submit", "reset", or "button". If not specified, the default type is "submit".
- **name**: Specifies the name of the button, which can be used when submitting a form.
- **value**: Specifies the value associated with the button, which is submitted along with the form data.
- **disabled**: Specifies that the button should be disabled and cannot be clicked by the user.
- **onclick**: Specifies a JavaScript function to be executed when the button is clicked.

Button controls are essential for creating interactive user interfaces in web applications. They can trigger form submissions, reset form fields, execute custom JavaScript functions, or navigate to different pages. With the appropriate styling and event handling, buttons can enhance the usability and functionality of your web pages.

Hidden Form Controls​

Hidden form controls are elements within an HTML form that are not visible to the user but are still submitted along with other visible form elements when the form is submitted. They are typically used to include additional data that does not need to be displayed to the user but is necessary for processing the form on the server-side.

To create a hidden form control in HTML, you can use the `<input>` element with its `type` attribute set to `"hidden"`. Here's an example:

<form action="submit.php" method="post">
<input type="hidden" name="user_id" value="123">
<input type="submit" value="Submit">
</form>

In this example, a hidden input field named "user_id" is included in the form with the value "123". When the form is submitted, the value of this hidden field will also be submitted to the server along with any other visible form fields.

Hidden form controls are commonly used for various purposes such as passing session identifiers, tracking information, or any other data that should not be visible or editable by the user. However, it's essential to keep in mind that although hidden form controls are not visible in the browser, their values can still be accessed and manipulated by users with some technical knowledge. Therefore, they should not be used for sensitive or security-critical data.
 
Top