-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path40.form_object.html
337 lines (247 loc) · 7.54 KB
/
40.form_object.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
<!DOCTYPE html>
<html>
<head>
<title>Form Object</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link type="text/css" href="styles.css" rel="stylesheet"/>
<link rel="stylesheet" href="https://www.w3schools.com/lib/w3.css">
<link href="prism.css" rel="stylesheet" />
<script src="scripts/prism.js"></script>
<style>
* {
box-sizing: border-box;
}
</style>
</head>
<body class="w3-margin">
<h1>Form Object</h1>
<h2>Submit Form</h2>
<p>Submit a form with a the submit() method:</p>
<form id="form1" action="">
First Name: <input type="text" name="fname" />
Last Name: <input type="text" name="lname" />
<input type="button" onclick="myFunction1()" value="Submit" />
</form>
<script>
function myFunction1() {
document.getElementById("form1").submit();
}
</script>
<pre><code class="language-javascript">
function myFunction1() {
document.getElementById("form1").submit();
}
</code></pre>
<hr />
<h2>Reset Form</h2>
<p>Reset a form with the reset() method:</p>
<form id="form2" action="">
First Name: <input type="text" name="fname" />
Last Name: <input type="text" name="lname" />
<input type="button" onclick="myFunction2()" value="Reset" />
</form>
<script>
function myFunction2() {
document.getElementById("form2").reset();
}
</script>
<pre><code class="language-javascript">
function myFunction2() {
document.getElementById("form2").reset();
}
</code></pre>
<hr />
<h2>Value</h2>
<p>Display the value of each element in a form using a for loop:</p>
<form id="form3" action="">
First Name: <input type="text" name="fname" value="Joe"/>
Last Name: <input type="text" name="lname" value="Blow"/>
<input type="submit" value="Submit" />
</form>
<br />
<button onclick="myFunction3()">Display Values</button>
<p id="demo3"></p>
<script>
function myFunction3() {
var x = document.getElementById("form3");
var txt = "";
var i;
for (i = 0; i < x.length; i++) {
txt += x.elements[i].value + " ";
}
document.getElementById("demo3").innerHTML = txt;
}
</script>
<pre><code class="language-javascript">
function myFunction3() {
var x = document.getElementById("form3");
var txt = "";
var i;
for (i = 0; i < x.length; i++) {
txt += x.elements[i].value + " ";
}
document.getElementById("demo3").innerHTML = txt;
}
</code></pre>
<hr />
<h2>Character Set</h2>
<p>Find the accepted character set of a form:</p>
<form id="form4" action="" accept-charset="ISO-8859-1">
First Name: <input type="text" name="fname" value="Daffy" />
Last Name: <input type="text" name="lname" value="Duck" />
</form>
<br />
<button onclick="myFunction4()">Get Charset</button>
<p id="demo4"></p>
<script>
function myFunction4() {
var x = document.getElementById("form4").acceptCharset;
document.getElementById("demo4").innerHTML = x;
}
</script>
<pre><code class="language-javascript">
function myFunction4() {
var x = document.getElementById("form4").acceptCharset;
document.getElementById("demo4").innerHTML = x;
}
</code></pre>
<hr />
<h2>Action Attribute</h2>
<p>Find the action attribute of a form:</p>
<form id="form5" action="example.php" accept-charset="ISO-8859-1">
First Name: <input type="text" name="fname" value="Daffy" />
Last Name: <input type="text" name="lname" value="Duck" />
</form>
<br />
<button onclick="myFunction5()">Get Action</button>
<p id="demo5"></p>
<script>
function myFunction5() {
var x = document.getElementById("form5").action;
document.getElementById("demo5").innerHTML = x;
}
</script>
<pre><code class="language-javascript">
function myFunction5() {
var x = document.getElementById("form5").action;
document.getElementById("demo5").innerHTML = x;
}
</code></pre>
<hr />
<h2>Encrypt Attribute</h2>
<p>Get the value of the encrypt attribute in a form:</p>
<form id="form6" action="#" method="post">
First Name: <input type="text" name="fname" value="Donald" />
Last Name: <input type="text" name="lname" value="Duck" />
<input type="submit" value="Submit" />
</form>
<br />
<button onclick="myFunction6()">Get Encrypt</button>
<p id="demo6"></p>
<script>
function myFunction6() {
var x = document.getElementById("form6").enctype;
document.getElementById("demo6").innerHTML = x;
}
</script>
<pre><code class="language-javascript">
function myFunction6() {
var x = document.getElementById("form6").enctype;
document.getElementById("demo6").innerHTML = x;
}
</code></pre>
<hr />
<h2>Elements</h2>
<p>Find the number of elements in a form:</p>
<form id="form7" action="#" method="post">
First Name: <input type="text" name="fname" value="Duffy" />
Last Name: <input type="text" name="lname" value="Dog" />
<input type="submit" value="Submit" />
</form>
<br />
<button onclick="myFunction7()">Get Elements #</button>
<p id="demo7"></p>
<script>
function myFunction7() {
var x = document.getElementById("form7").length;
document.getElementById("demo7").innerHTML = x;
}
</script>
<pre><code class="language-javascript">
function myFunction7() {
var x = document.getElementById("form7").length;
document.getElementById("demo7").innerHTML = x;
}
</code></pre>
<hr />
<h2>Method</h2>
<p>Get the method for sending form data:</p>
<form id="form8" action="#" method="get">
First Name: <input type="text" name="fname" value="Duffy" />
Last Name: <input type="text" name="lname" value="Dog" />
<input type="submit" value="Submit" />
</form>
<br />
<button onclick="myFunction8()">Find Method</button>
<p id="demo8"></p>
<script>
function myFunction8() {
var x = document.getElementById("form8").method;
document.getElementById("demo8").innerHTML = x;
}
</script>
<pre><code class="language-javascript">
function myFunction8() {
var x = document.getElementById("form8").method;
document.getElementById("demo8").innerHTML = x;
}
</code></pre>
<hr />
<h2>Name</h2>
<p>Find the name of a form:</p>
<form action="" name="myForm" id="form9">
First Name: <input type="text" name="fname" value="Joe" />
Last Name: <input type="text" name="lname" value="Blow" />
<input type="submit" value="Submit" />
</form>
<br />
<button onclick="myFunction9()">Get Name</button>
<p id="demo9"></p>
<script>
function myFunction9() {
var x = document.getElementById("form9").name;
document.getElementById("demo9").innerHTML = x;
}
</script>
<pre><code class="language-javascript">
function myFunction9() {
var x = document.getElementById("form9").name;
document.getElementById("demo9").innerHTML = x;
}
</code></pre>
<hr />
<h2>Target</h2>
<p>Find the target of a form:</p>
<form id="form10" action="" target="_self">
First Name: <input type="text" name="fname" value="Billy" />
Last Name: <input type="text" name="lname" value="Bob" />
<input type="submit" value="Submit" />
</form>
<br />
<button onclick="myFunction10()">Get Target</button>
<p id="demo10"></p>
<script>
function myFunction10() {
var x = document.getElementById("form10").target;
document.getElementById("demo10").innerHTML = x;
}
</script>
<pre><code class="language-javascript">
function myFunction10() {
var x = document.getElementById("form10").target;
document.getElementById("demo10").innerHTML = x;
}
</code></pre>
</body>
</html>