[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ja/docs/Web/API/HTMLFormElement/elements [Back]  [Original]

HTMLFormElement: elements - Web API | MDN

MDN Web Docs

View in English Always switch to English

HTMLFormElement: elements

Baseline

20157

HTMLFormElement elements HTMLFormControlsCollection <form>

length

name id

HTML 5 HTMLCollection HTMLFormControlsCollection

: forms

HTMLFormControlsCollection

ID

html
<form id="my-form">
  <label>
    :
    <input type="text" name="username" />
  </label>
  <label>
    :
    <input type="text" name="full-name" />
  </label>
  <label>
    :
    <input type="password" name="password" />
  </label>
</form>
js
const inputs = document.getElementById("my-form").elements;
const inputByIndex = inputs[0];
const inputByName = inputs["username"];

"text" <input>

js
const inputs = document.getElementById("my-form").elements;

// Iterate over the form controls
for (let i = 0; i < inputs.length; i++) {
  if (inputs[i].nodeName === "INPUT" && inputs[i].type === "text") {
    // Update text input
    inputs[i].value.toLocaleUpperCase();
  }
}

js
const inputs = document.getElementById("my-form").elements;

// Iterate over the form controls
for (let i = 0; i < inputs.length; i++) {
  // Disable all form controls
  inputs[i].setAttribute("disabled", "");
}

HTML
# dom-form-elements-dev


Web Proxy Viewer  |  New URL  |  Original Page