diff --git a/2-ui/4-forms-controls/1-form-elements/1-add-select-option/solution.md b/2-ui/4-forms-controls/1-form-elements/1-add-select-option/solution.md index 80fad3850..997c98812 100644 --- a/2-ui/4-forms-controls/1-form-elements/1-add-select-option/solution.md +++ b/2-ui/4-forms-controls/1-form-elements/1-add-select-option/solution.md @@ -1,9 +1,9 @@ -The solution, step by step: +Рішення, крок за кроком: ```html run ``` -There may be multiple elements with the same name. This is typical with radio buttons and checkboxes. +У колекції може бути кілька елементів з однаковим ім’ям (`name`). Це типово для перемикачів (radio buttons) та чекбоксів (checkboxes). -In that case, `form.elements[name]` is a *collection*. For instance: +В такому випадку `form.elements[name]` -- це *колекція*. Наприклад: ```html run height=40
@@ -57,13 +57,12 @@ alert(ageElems[0]); // [object HTMLInputElement] ``` -These navigation properties do not depend on the tag structure. All control elements, no matter how deep they are in the form, are available in `form.elements`. +Ці властивості навігації не залежать від структури тегів в середині форми. Усі елементи керування, незалежно від того, наскільки глибоко вони розташовані у формі, доступні в колекції `form.elements`. +````smart header="Елементи `
` як \"підформи\"" +Форма може містити всередині один або кілька елементів `
`. Вони також мають властивість `elements`, яка містить колекцію елементів керування всередині них. -````smart header="Fieldsets as \"subforms\"" -A form may have one or many `
` elements inside it. They also have `elements` property that lists form controls inside them. - -For instance: +Наприклад: ```html run height=80 @@ -81,7 +80,7 @@ For instance: let fieldset = form.elements.userFields; alert(fieldset); // HTMLFieldSetElement - // we can get the input by name both from the form and from the fieldset + // ми можемо отримати поле за іменем як з форми, так і з елементу fieldset alert(fieldset.elements.login == form.elements.login); // true */!* @@ -89,14 +88,14 @@ For instance: ``` ```` -````warn header="Shorter notation: `form.name`" -There's a shorter notation: we can access the element as `form[index/name]`. +````warn header="Коротший варіант: `form.name`" +Існує коротший варіант запису: ми можемо отримати доступ до елемента через `form[index/name]`. -In other words, instead of `form.elements.login` we can write `form.login`. +Іншими словами, замість `form.elements.login` ми можемо написати `form.login`. -That also works, but there's a minor issue: if we access an element, and then change its `name`, then it is still available under the old name (as well as under the new one). +Такий варіант також працює, але є незначна проблема: якщо ми отримуємо доступ до елемента, а потім змінюємо його ім’я (`name`), то він все ще буде доступний під старим ім’ям (а також під новим). -That's easy to see in an example: +Це легко побачити на прикладі: ```html run height=40 @@ -104,34 +103,33 @@ That's easy to see in an example: ``` -That's usually not a problem, however, because we rarely change names of form elements. - +Однак це зазвичай не проблема, оскільки ми рідко змінюємо імена елементів форми. ```` -## Backreference: element.form +## Зворотне посилання: element.form -For any element, the form is available as `element.form`. So a form references all elements, and elements reference the form. +Для будь-якого елемента форми, сама форма доступна у властивості `element.form`. Таким чином, форма посилається на всі елементи, а елементи посилаються на форму. -Here's the picture: +Ось картинка: ![](form-navigation.svg) -For instance: +Наприклад: ```html run height=40
@@ -149,76 +147,76 @@ For instance: ``` -## Form elements +## Елементи форми -Let's talk about form controls. +Розглянемо елементи керування формою. -### input and textarea +### input та textarea -We can access their value as `input.value` (string) or `input.checked` (boolean) for checkboxes. +Ми можемо отримати доступ до їх значення через властивість `input.value` (рядок) або `input.checked` (логічне значення) для чекбоксів. -Like this: +Ось так: ```js input.value = "New value"; textarea.value = "New text"; -input.checked = true; // for a checkbox or radio button +input.checked = true; // для чекбокса або перемикача (radio button) ``` -```warn header="Use `textarea.value`, not `textarea.innerHTML`" -Please note that even though `` holds its value as nested HTML, we should never use `textarea.innerHTML` to access it. +```warn header="Використовуйте `textarea.value` замість `textarea.innerHTML`" +Зауважте, що, попри те, що `` зберігає своє значення як вкладений HTML, ми ніколи не повинні використовувати `textarea.innerHTML` для доступу до нього. -It stores only the HTML that was initially on the page, not the current value. +Властивість `innerHTML` містить лише початковий HTML, а не поточне значення. ``` -### select and option +### select та option -A `` має 3 важливі властивості: -1. `select.options` -- the collection of ` - - + + + ``` -The full specification of the `` доступна в специфікації . ### new Option -In the [specification](https://html.spec.whatwg.org/multipage/forms.html#the-option-element) there's a nice short syntax to create an ` +// створює ``` -The same option, but selected: +Та сама опція, але обрана: ```js let option = new Option("Text", "value", true, true); ``` -Option elements have properties: +Елементи `