Att Form Name
# HTML
```
### Example 2: Accessing Form Elements Directly
When a form has a `name` attribute, you can also access its child input elements directly through the form object in JavaScript:
```javascript
// Access the input element named "fname" inside the form named "myForm"
let firstNameValue = document.myForm.fname.value;
console.log(firstNameValue);
```
---
## Best Practices and Considerations
* **Uniqueness:** While not strictly enforced by browsers, the `name` value should be unique within the HTML document to avoid conflicts when referencing elements in JavaScript.
* **Name vs. ID:**
* Use `id` for CSS styling and general DOM manipulation (`document.getElementById()`).
* Use `name` for form submission data handling and legacy DOM form collections (`document.forms`).
* **Avoid Reserved Words:** Do not use JavaScript reserved keywords (such as `submit`, `reset`, or `history`) as the value for the `name` attribute, as this can overwrite built-in form methods and cause unexpected scripting errors.
YouTip