You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Forms and control elements, such as `<input>`have a lot of special properties and events.
3
+
فرمها و control elementها مثل `<input>`دارای prperty و eventهای ویژهای هستند.
4
4
5
-
Working with forms will be much more convenient when we learn them.
5
+
وقتی فرمها را یاد بگیریم، کار کردن با آنها بسیار راحتتر میشود.
6
6
7
7
## Navigation: form and elements
8
8
9
-
Document forms are members of the special collection `document.forms`.
9
+
فرمهای document از اعضای مجموعهی ویژهی `document.forms` هستند.
10
+
11
+
این به اصطلاح یک مجموعهی نامگذاری شده است: هم نامگذاری شده و هم ترتیبدار شده است. برای دسترسی به فرم میتوانیم هم از نام آن و هم از شمارهی آن در document استفاده کنیم.
10
12
11
-
That's a so-called *"named collection"*: it's both named and ordered. We can use both the name or the number in the document to get the form.
12
13
13
14
```js no-beautify
14
-
document.forms.my; //the form with name="my"
15
-
document.forms[0]; //the first form in the document
15
+
document.forms.my; // "my" = فرم با نام
16
+
document.forms[0]; //document اولین فرم در
16
17
```
17
18
18
-
When we have a form, then any element is available in the named collection`form.elements`.
19
+
وقتی یک فرم داریم، در این صورت هر elementای در مجموعهی نامگذاری شده با`form.elements` قابل دسترسی است.
19
20
20
-
For instance:
21
+
برای مثال:
21
22
22
23
```html run height=40
23
24
<formname="my">
@@ -26,19 +27,19 @@ For instance:
26
27
</form>
27
28
28
29
<script>
29
-
//get the form
30
+
// form گرفتن
30
31
let form =document.forms.my; // <form name="my"> element
31
32
32
-
//get the element
33
+
// element گرفتن
33
34
let elem =form.elements.one; // <input name="one"> element
34
35
35
36
alert(elem.value); // 1
36
37
</script>
37
38
```
38
39
39
-
There may be multiple elements with the same name. This is typical with radio buttons and checkboxes.
40
+
ممکن است elementهای زیادی با نام یکسان وجود داشته باشند. این در مورد radio buttonها و checkboxها معمول است.
40
41
41
-
In that case,`form.elements[name]`is a *collection*. For instance:
42
+
در آن صورت،`form.elements[name]`یک *مجموعه*است. برای مثال:
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`.
61
+
این navigation propertyها به tag structure وابستگی ندارند. تمام control elementها، فرقی ندارد چقدر در فرم عمیق باشند، در `form.elements` قابل دسترسی هستند.
61
62
62
63
63
64
````smart header="Fieldsets as \"subforms\""
64
-
A form may have one or many `<fieldset>` elements inside it. They also have `elements` property that lists form controls inside them.
65
+
.را درون خود فهرست میکنند form controls دارند که `elements` property در خودش داشته باشد. آنها همچنین `<fieldset>` elements یک فرم ممکن است یک یا چند
65
66
66
67
For instance:
67
68
@@ -81,57 +82,57 @@ For instance:
81
82
let fieldset = form.elements.userFields;
82
83
alert(fieldset); // HTMLFieldSetElement
83
84
84
-
// we can get the input by name both from the form and from the fieldset
85
+
// .دریافت کنیم fieldset و هم از form را با نام هم از input ما میتوانیم
There's a shorter notation: we can access the element as`form[index/name]`.
93
+
````warn header="نماد کوتاهتر: `form.name`"
94
+
.دسترسی داشته باشیم element به`form[index/name]` کوتاهتر هم وجود دارد: ما میتوانیم با notation یک
94
95
95
-
In other words, instead of`form.elements.login`we can write `form.login`.
96
+
به عبارت دیگر، به جای`form.elements.login`میتوانیم بنویسیم `form.login`.
96
97
97
-
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).
98
+
آن هم کار میکند، ولی یک مشکل جزئی وجود دارد: اگر به یک element دسترسی داشته باشیم، و بعد `name` آن را تغییر بدهیم، آنگاه آن هنوز با نام قدیمی قابل دسترسی است (همچنین با نام جدید)
98
99
99
-
That's easy to see in an example:
100
+
آسانتر است که آن را در یک مثال ببینیم:
100
101
101
102
```html run height=40
102
103
<formid="form">
103
104
<inputname="login">
104
105
</form>
105
106
106
107
<script>
107
-
alert(form.elements.login==form.login); // true, the same <input>
108
+
alert(form.elements.login==form.login); // true, همان <input>
108
109
109
-
form.login.name="username"; //change the name of the input
110
+
form.login.name="username"; //را تغییر میدهد input نام
110
111
111
-
//form.elements updated the name:
112
+
//میکند update را name، forms.elements
112
113
alert(form.elements.login); // undefined
113
114
alert(form.elements.username); // input
114
115
115
116
*!*
116
-
//form allows both names: the new one and the old one
117
+
//را مجاز میکند: هم جدید و هم قدیمی name فرم هر دو
117
118
alert(form.username==form.login); // true
118
119
*/!*
119
120
</script>
120
121
```
121
122
122
-
That's usually not a problem, however, because we rarely change names of form elements.
123
+
با این حال، این معمولا یک مشکل نیست، چون ما به ندرت نام elementهای فرم را تغییر میدهیم.
123
124
124
125
````
125
126
126
127
## Backreference: element.form
127
128
128
-
For any element, the form is available as `element.form`. So a form references all elements, and elements reference the form.
129
+
برای هر elementای، فرم به عنوان `element.form` قابل دسترسی است. بنابراین یک فرم به همهی elementها ارجاع میدهد و elementها هم به فرم ارجاع میدهند.
129
130
130
-
Here's the picture:
131
+
این هم تصویرش است:
131
132
132
133

133
134
134
-
For instance:
135
+
برای مثال:
135
136
136
137
```html run height=40
137
138
<form id="form">
@@ -151,64 +152,64 @@ For instance:
151
152
152
153
## Form elements
153
154
154
-
Let's talk about form controls.
155
+
.صحبت کنیم form controls بیایید دربارهی
155
156
156
157
### input and textarea
157
158
158
-
We can access their value as `input.value` (string) or `input.checked` (boolean) for checkboxes and radio buttons.
159
+
.به مقدار آنها دسترسی داشته باشیم radio buttons و checkboxes برای `input.value` (string) یا `input.checked` (boolean) ما میتوانیم با
159
160
160
-
Like this:
161
+
مثل این:
161
162
162
163
```js
163
-
input.value = "New value";
164
-
textarea.value = "New text";
164
+
input.value = "جدید value";
165
+
textarea.value = "جدید text";
165
166
166
-
input.checked = true; // for a checkbox or radio button
167
+
input.checked = true; // radio button یا checkbox برای یک
167
168
```
168
169
169
-
```warn header="Use `textarea.value`, not `textarea.innerHTML`"
170
-
Please note that even though `<textarea>...</textarea>` holds its value as nested HTML, we should never use `textarea.innerHTML` to access it.
170
+
```warn header="Use `textarea.value`, نه `textarea.innerHTML`"
171
+
.به آن دسترسی داشته باشیم `textarea.innerHTML` تو در تو حفظ میکند اما ما هرگز نباید از طریق HTML مقدار خود را به عنوان `<textarea>...</textarea>` لطفا توجه کنید که با اینکه
171
172
172
-
It stores only the HTML that was initially on the page, not the current value.
173
+
.که در ابتدا در صفحه بوده را ذخیره میکند، نه مقدار فعلی را HTML آن فقط
173
174
```
174
175
175
-
### select and option
176
+
### select و option
176
177
177
-
A `<select>` element has 3 important properties:
178
+
:مهم دارد property سه `<select>` element یک
178
179
179
-
1. `select.options` -- the collection of `<option>` subelements,
180
-
2. `select.value` -- the *value* of the currently selected `<option>`,
181
-
3. `select.selectedIndex` -- the *number* of the currently selected `<option>`.
180
+
1. `select.options` -- `<option>` subelements مجموعهای از
181
+
2. `select.value` -- در حال حاضر انتخاب شده `<option>` *مقدار*
182
+
3. `select.selectedIndex` -- در حال حاضر انتخاب شده `<option>` *تعداد*
182
183
183
-
They provide three different ways of setting a value for a `<select>`:
184
+
:عرضه میکنند `<select>` کردن یک مقدار برای set آنها سه راه مختلف برای
184
185
185
-
1. Find the corresponding `<option>` element (e.g. among `select.options`) and set its `option.selected` to `true`.
186
-
2. If we know a new value: set `select.value` to the new value.
187
-
3. If we know the new option number: set `select.selectedIndex` to that number.
186
+
1. .قرار میدهد `true` آن را برابر `option.selected` و مقدار (برای مثال `select.options`) متناظر را پیدا میکند `<option>` عنصر
187
+
2. .را برابر آن مقدار جدید قرار میدهد `select.value` اگر یک مقدار جدید را بدانیم:
188
+
3. .را برابر آن عدد قرار میدهد `select.selectedIndex` جدید را بدانیم: مقدار option number اگر
188
189
189
-
Here is an example of all three methods:
190
+
:اینجا مثالی از هر سه متد میبینیم
190
191
191
192
```html run
192
193
<select id="select">
193
-
<option value="apple">Apple</option>
194
-
<option value="pear">Pear</option>
195
-
<option value="banana">Banana</option>
194
+
<option value="apple">سیب</option>
195
+
<option value="pear">گلابی</option>
196
+
<option value="banana">موز</option>
196
197
</select>
197
198
198
199
<script>
199
-
// all three lines do the same thing
200
+
// تمام سه خط کار یکسانی انجام میدهند
200
201
select.options[2].selected = true;
201
202
select.selectedIndex = 2;
202
203
select.value = 'banana';
203
-
// please note: options start from zero, so index 2 means the 3rd option.
204
+
// .option از صفر شروع میشوند، پس اندیس دو یعنی سومین options :لطفا دقت داشته باشید
204
205
</script>
205
206
```
206
207
207
-
Unlike most other controls, `<select>` allows to select multiple options at once if it has `multiple` attribute. This attribute is rarely used, though.
208
+
.به ندرت استفاده میشود attribute به طور همزمان انتخاب شوند. با این حال، این option داشته باشد، اجازه میدهد که چند attribute `چند` `<select>` های دیگر اگرcontrol برعکس بیشتر
208
209
209
-
For multiple selected values, use the first way of setting values: add/remove the `selected` property from `<option>` subelements.
210
+
.حذف/به آن اضافه کنید `<option>` subelements را از `selected` property برای چندین مقدار انتخاب شده، از روش اول برای تنظیم مقادیر استفاده کنید
210
211
211
-
Here's an example of how to get selected values from a multi-select:
212
+
:مقدار انتخابشده را به دست آوریم ،multi-select اینجا یک مثال داریم از اینکه چگونه از یک
212
213
213
214
```html run
214
215
<select id="select" *!*multiple*/!*>
@@ -218,7 +219,7 @@ Here's an example of how to get selected values from a multi-select:
218
219
</select>
219
220
220
221
<script>
221
-
// get all selected values from multi-select
222
+
// multi-select گرفتن تمام مقادیر انتخابشده از
222
223
let selected = Array.from(select.options)
223
224
.filter(option => option.selected)
224
225
.map(option => option.value);
@@ -227,72 +228,72 @@ Here's an example of how to get selected values from a multi-select:
227
228
</script>
228
229
```
229
230
230
-
The full specification of the `<select>` element is available in the specification <https://html.spec.whatwg.org/multipage/forms.html#the-select-element>.
231
+
.موجود است <https://html.spec.whatwg.org/multipage/forms.html#the-select-element> در مشخصات `<select>` element مشخصات کامل
231
232
232
-
### new Option
233
+
### جدید Option
233
234
234
-
In the [specification](https://html.spec.whatwg.org/multipage/forms.html#the-option-element) there's a nice short syntax to create an `<option>` element:
235
+
:وجود دارد <option>` element کوتاه و زیبا برای ایجاد یک syntax یک [مشخصات](https://html.spec.whatwg.org/multipage/forms.html#the-option-element) در
235
236
236
237
```js
237
238
option = new Option(text, value, defaultSelected, selected);
238
239
```
239
240
240
-
This syntax is optional. We can use `document.createElement('option')` and set attributes manually. Still, it may be shorter, so here are the parameters:
241
+
:را به صورت دستی مقداردهی کنیم. با این حال، ممکن است کوتاهتر باشد پس اینجا پارامترها وجود دارند attributes استقاده کنیم و `document.createElement('option')` اختیاری است، ما میتوانیم از syntax این
241
242
242
-
- `text` -- the text inside the option,
243
-
- `value` -- the option value,
244
-
- `defaultSelected` -- if `true`, then `selected` HTML-attribute is created,
245
-
- `selected` -- if `true`, then the option is selected.
243
+
- `text` -- option متن درون,
244
+
- `value` -- option مقدار,
245
+
- `defaultSelected` -- ایجاد میشود `selected` HTML-attribute باشد `true` اگر
246
+
- `selected` -- انتخاب میشود option باشد `true` اگر
246
247
247
-
The difference between `defaultSelected` and `selected` is that `defaultSelected` sets the HTML-attribute (that we can get using `option.getAttribute('selected')`, while `selected` sets whether the option is selected or not.
248
+
.انتخاب شده است یا نه option مشخص میکند که آیا `selected` در حالی که (آن را بگیریم `option.getAttribute('selected')` که ما میتوانیم با) میکند set را HTML-attribute مقدار `defaultSelected` در این است که `selected` و `defaultSelected` تفاوت بین
248
249
249
-
In practice, one should usually set _both_ values to `true` or `false`. (Or, simply omit them; both default to `false`.)
250
+
(`false` یا به سادگی حذف شوند، مقدار پیشفرض هر دو) .باشند `false` یا `true` در عمل باید معمولا _هر دو_ مقدار
250
251
251
-
For instance, here's a new "unselected" option:
252
+
برای مثال، اینجا بک "unselected" option داریم:
252
253
253
254
```js
254
255
let option = new Option("Text", "value");
255
-
// creates <option value="value">Text</option>
256
+
// ایجاد میکند <option value="value">Text</option>
256
257
```
257
258
258
-
The same option, but selected:
259
+
شده select اما option همان
259
260
260
261
```js
261
262
let option = new Option("Text", "value", true, true);
262
263
```
263
264
264
-
Option elements have properties:
265
+
:دارند property یک سری Option elements
265
266
266
267
`option.selected`
267
-
: Is the option selected.
268
+
: انتخاب شده است یا نه option
268
269
269
270
`option.index`
270
-
: The number of the option among the others in its `<select>`.
271
+
خودش `<select>` در بین بقیه option عدد :
271
272
272
273
`option.text`
273
-
: Text content of the option (seen by the visitor).
274
+
(توسط بازدیدکننده دیده میشود) option محتوای متنی :
: A form is available as `document.forms[name/index]`.
285
+
.قابل دسترسی است `document.forms[name/index]` یک فرم با :
285
286
286
287
`form.elements`
287
-
: Form elements are available as `form.elements[name/index]`, or can use just `form[name/index]`. The `elements` property also works for `<fieldset>`.
288
+
.کار میکنند `<fieldset>` همچنین با `elements` property استفاده کرد. `form[name/index]` قابل دسترسی هستند، یا فقط میتوان از `form.elements[name/index]` با Form elements عناصر :
288
289
289
290
`element.form`
290
-
: Elements reference their form in the `form` property.
291
+
.به فرم خود ارجاع میدهند `form` property عناصر در :
291
292
292
-
Value is available as `input.value`, `textarea.value`, `select.value`, etc. (For checkboxes and radio buttons, use `input.checked` to determine whether a value is selected.)
293
+
(.استفاده کنید که مشخص میکند یک مقدار انتخاب شده است یا نه `input.checked` از radio buttons و checkboxes برای) و ... قابل دسترسی است. `input.value`، `textarea.value`، `select.value` با value مقدار
293
294
294
-
For `<select>`, one can also get the value by the index `select.selectedIndex` or through the options collection `select.options`.
295
+
.به دست آورد options collection `select.options` یا از طریق `select.selectedIndex` همچنین میتوان مقدار را با اندیس `<select>` برای
295
296
296
-
These are the basics to start working with forms. We'll meet many examples further in the tutorial.
297
+
اینها مبانی شروع کار با فرمها هستند. ما مثالهای بیشتری را در آموزش خواهیم دید.
297
298
298
-
In the next chapter we'll cover `focus` and `blur` events that may occur on any element, but are mostly handled on forms.
299
+
.را پوشش خواهیم داد که ممکن است در هر عنصری اتفاق بیفتند، اما بیشتر در فرمها مدیریت میشوند `blur` و `focus` در فصل بعدی ما
0 commit comments