-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathf12.html
604 lines (567 loc) · 19.8 KB
/
f12.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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>HTML - Forms</title>
<link rel="shortcut icon" sizes="200*200" type="image/x-icon" href="logo1.jpg">
</head>
<body style="background-color: aliceblue;color:rgb(90, 46, 194)">
<h2>HTML - Forms</h2>
<div class="clearer"></div>
<p>HTML Forms are required, when you want to collect some data from the site visitor. For example, during user registration you would like to collect information such as name, email address, credit card, etc.</p>
<p>A form will take input from the site visitor and then will post it to a back-end application such as CGI, ASP Script or PHP script etc. The back-end application will perform required processing on the passed data based on defined business logic inside the application.</p>
<p>There are various form elements available like text fields, textarea fields, drop-down menus, radio buttons, checkboxes, etc.</p>
<p>The HTML <b><form></b> tag is used to create an HTML form and it has following syntax −</p>
<pre style="background-color:azure; class="result notranslate">
<form action = "Script URL" method = "GET|POST">
form elements like input, textarea etc.
</form>
</pre>
<h2>Form Attributes</h2>
<p>Apart from common attributes, following is a list of the most frequently used form attributes −</p>
<table class="table table-bordered">
<tr>
<th>Sr.No</th>
<th style="text-align:center;">Attribute & Description</th>
</tr>
<tr>
<td class="ts">1</td>
<td>
<p><b>action</b></p>
<p>Backend script ready to process your passed data.</p></td>
</tr>
<tr>
<td class="ts">2</td>
<td>
<p><b>method</b></p>
<p>Method to be used to upload data. The most frequently used are GET and POST methods.</p></td>
</tr>
<tr>
<td class="ts">3</td>
<td>
<p><b>target</b></p>
<p>Specify the target window or frame where the result of the script will be displayed. It takes values like _blank, _self, _parent etc.</p></td>
</tr>
<tr>
<td class="ts">4</td>
<td>
<p><b>enctype</b></p>
<p>You can use the enctype attribute to specify how the browser encodes the data before it sends it to the server. Possible values are −</p>
<p><b>application/x-www-form-urlencoded</b> − This is the standard method most forms use in simple scenarios.</p>
<p><b>mutlipart/form-data</b> − This is used when you want to upload binary data in the form of files like image, word file etc.</p>
</td>
</tr>
</table>
<p><b>Note</b> − You can refer to <a href="/perl/perl_cgi_programming.htm">Perl & CGI</a> for a detail on how form data upload works.</p>
<h2>HTML Form Controls</h2>
<p>There are different types of form controls that you can use to collect data using HTML form −</p>
<ul class="list">
<li>Text Input Controls</li>
<li>Checkboxes Controls</li>
<li>Radio Box Controls</li>
<li>Select Box Controls</li>
<li>File Select boxes</li>
<li>Hidden Controls</li>
<li>Clickable Buttons</li>
<li>Submit and Reset Button</li>
</ul>
<h2>Text Input Controls</h2>
<p>There are three types of text input used on forms −</p>
<ul class="list">
<li><p><b>Single-line text input controls</b> − This control is used for items that require only one line of user input, such as search boxes or names. They are created using HTML <b><input></b> tag.</p></li>
<li><p><b>Password input controls</b> − This is also a single-line text input but it masks the character as soon as a user enters it. They are also created using HTMl <input> tag.</p></li>
<li><p><b>Multi-line text input controls</b> − This is used when the user is required to give details that may be longer than a single sentence. Multi-line input controls are created using HTML <b><textarea></b> tag.</p></li>
</ul>
<h2>Single-line text input controls</h2>
<p>This control is used for items that require only one line of user input, such as search boxes or names. They are created using HTML <input> tag.</p>
<h3>Example</h3>
<p>Here is a basic example of a single-line text input used to take first name and last name −</p>
<pre style="background-color:azure; class="prettyprint notranslate">
<!DOCTYPE html>
<html>
<head>
<title>Text Input Control</title>
</head>
<body>
<form >
First name: <input type = "text" name = "first_name" />
<br>
Last name: <input type = "text" name = "last_name" />
</form>
</body>
</html>
</pre>
</div>
<a target="_blank" href="f12-1.html" class="w3-btn w3-margin-bottom"><button style="background-color:rgb(115, 126, 226);">Try it Yourself</button> »</a>
</div>
<h2>Attributes</h2>
<p>Following is the list of attributes for <input> tag for creating text field.</p>
<table class="table table-bordered">
<tr>
<th>Sr.No</th>
<th style="text-align:center;">Attribute & Description</th>
</tr>
<tr>
<td class="ts">1</td>
<td>
<p><b>type</b></p>
<p>Indicates the type of input control and for text input control it will be set to <b>text</b>.</p></td>
</tr>
<tr>
<td class="ts">2</td>
<td>
<p><b>name</b></p>
<p>Used to give a name to the control which is sent to the server to be recognized and get the value.</p></td>
</tr>
<tr>
<td class="ts">3</td>
<td>
<p><b>value</b></p>
<p>This can be used to provide an initial value inside the control.</p></td>
</tr>
<tr>
<td class="ts">4</td>
<td>
<p><b>size</b></p>
<p>Allows to specify the width of the text-input control in terms of characters.</p></td>
</tr>
<tr>
<td class="ts">5</td>
<td>
<p><b>maxlength</b></p>
<p>Allows to specify the maximum number of characters a user can enter into the text box.</p></td>
</tr>
</table>
<h2>Password input controls</h2>
<p>This is also a single-line text input but it masks the character as soon as a user enters it. They are also created using HTML <input>tag but type attribute is set to <b>password</b>.</p>
<h3>Example</h3>
<p>Here is a basic example of a single-line password input used to take user password −</p>
<pre style="background-color:azure; class="prettyprint notranslate">
<!DOCTYPE html>
<html>
<head>
<title>Password Input Control</title>
</head>
<body>
<form >
User ID : <input type = "text" name = "user_id" />
<br>
Password: <input type = "password" name = "password" />
</form>
</body>
</html>
</pre>
</div>
<a target="_blank" href="f12-2.html" class="w3-btn w3-margin-bottom"><button style="background-color:rgb(115, 126, 226);">Try it Yourself</button> »</a>
</div>
<h2>Attributes</h2>
<p>Following is the list of attributes for <input> tag for creating password field.</p>
<table class="table table-bordered">
<tr>
<th>Sr.No</th>
<th style="text-align:center;">Attribute & Description</th>
</tr>
<tr>
<td class="ts">1</td>
<td>
<p><b>type</b></p>
<p>Indicates the type of input control and for password input control it will be set to <b>password</b>.</p>
</td>
</tr>
<tr>
<td class="ts">2</td>
<td>
<p><b>name</b></p>
<p>Used to give a name to the control which is sent to the server to be recognized and get the value.</p>
</td>
</tr>
<tr>
<td class="ts">3</td>
<td>
<p><b>value</b></p>
<p>This can be used to provide an initial value inside the control.</p>
</td>
</tr>
<tr>
<td class="ts">4</td>
<td>
<p><b>size</b></p>
<p>Allows to specify the width of the text-input control in terms of characters.</p>
</td>
</tr>
<tr>
<td class="ts">5</td>
<td>
<p><b>maxlength</b></p>
<p>Allows to specify the maximum number of characters a user can enter into the text box.</p>
</td>
</tr>
</table>
<h2>Multiple-Line Text Input Controls</h2>
<p>This is used when the user is required to give details that may be longer than a single sentence. Multi-line input controls are created using HTML <textarea> tag.</p>
<h3>Example</h3>
<p>Here is a basic example of a multi-line text input used to take item description −</p>
<pre style="background-color:azure; class="prettyprint notranslate">
<!DOCTYPE html>
<html>
<head>
<title>Multiple-Line Input Control</title>
</head>
<body>
<form>
Description : <br />
<textarea rows = "5" cols = "50" name = "description">
Enter description here...
</textarea>
</form>
</body>
</html>
</pre>
</div>
<a target="_blank" href="f12-3.html" class="w3-btn w3-margin-bottom"><button style="background-color:rgb(115, 126, 226);">Try it Yourself</button> »</a>
</div>
<h2>Attributes</h2>
<p>Following is the list of attributes for <textarea> tag.</p>
<table class="table table-bordered">
<tr>
<th>Sr.No</th>
<th style="text-align:center;">Attribute & Description</th>
</tr>
<tr>
<td class="ts">1</td>
<td>
<p><b>name</b></p>
<p>Used to give a name to the control which is sent to the server to be recognized and get the value.</p>
</td>
</tr>
<tr>
<td class="ts">2</td>
<td>
<p><b>rows</b></p>
<p>Indicates the number of rows of text area box.</p>
</td>
</tr>
<tr>
<td class="ts">3</td>
<td>
<p><b>cols</b></p>
<p>Indicates the number of columns of text area box</p>
</td>
</tr>
</table>
<h2>Checkbox Control</h2>
<p>Checkboxes are used when more than one option is required to be selected. They are also created using HTML <input> tag but type attribute is set to <b>checkbox.</b>.</p>
<h3>Example</h3>
<p>Here is an example HTML code for a form with two checkboxes −</p>
<pre style="background-color:azure; class="prettyprint notranslate">
<!DOCTYPE html>
<html>
<head>
<title>Checkbox Control</title>
</head>
<body>
<form>
<input type = "checkbox" name = "maths" value = "on"> Maths
<input type = "checkbox" name = "physics" value = "on"> Physics
</form>
</body>
</html>
</pre>
</div>
<a target="_blank" href="f12-4.html" class="w3-btn w3-margin-bottom"><button style="background-color:rgb(115, 126, 226);">Try it Yourself</button> »</a>
</div>
<h2>Attributes</h2>
<p>Following is the list of attributes for <checkbox> tag.</p>
<table class="table table-bordered">
<tr>
<th>Sr.No</th>
<th style="text-align:center;">Attribute & Description</th>
</tr>
<tr>
<td class="ts">1</td>
<td>
<p><b>type</b></p>
<p>Indicates the type of input control and for checkbox input control it will be set to <b>checkbox.</b>.</p>
</td>
</tr>
<tr>
<td class="ts">2</td>
<td>
<p><b>name</b></p>
<p>Used to give a name to the control which is sent to the server to be recognized and get the value.</p>
</td>
</tr>
<tr>
<td class="ts">3</td>
<td>
<p><b>value</b></p>
<p>The value that will be used if the checkbox is selected.</p>
</td>
</tr>
<tr>
<td class="ts">4</td>
<td>
<p><b>checked</b></p>
<p>Set to <i>checked</i> if you want to select it by default.</p>
</td>
</tr>
</table>
<h2>Radio Button Control</h2>
<p>Radio buttons are used when out of many options, just one option is required to be selected. They are also created using HTML <input> tag but type attribute is set to <b>radio</b>.</p>
<h3>Example</h3>
<p>Here is example HTML code for a form with two radio buttons −</p>
<pre style="background-color:azure; class="prettyprint notranslate">
<!DOCTYPE html>
<html>
<head>
<title>Radio Box Control</title>
</head>
<body>
<form>
<input type = "radio" name = "subject" value = "maths"> Maths
<input type = "radio" name = "subject" value = "physics"> Physics
</form>
</body>
</html>
</pre>
</div>
<a target="_blank" href="f12-5.html" class="w3-btn w3-margin-bottom"><button style="background-color:rgb(115, 126, 226);">Try it Yourself</button> »</a>
</div>
<h2>Attributes</h2>
<p>Following is the list of attributes for radio button.</p>
<table class="table table-bordered">
<tr>
<th>Sr.No</th>
<th style="text-align:center;">Attribute & Description</th>
</tr>
<tr>
<td class="ts">1</td>
<td>
<p><b>type</b></p>
<p>Indicates the type of input control and for checkbox input control it will be set to radio.</p>
</td>
</tr>
<tr>
<td class="ts">2</td>
<td>
<p><b>name</b></p>
<p>Used to give a name to the control which is sent to the server to be recognized and get the value.</p>
</td>
</tr>
<tr>
<td class="ts">3</td>
<td>
<p><b>value</b></p>
<p>The value that will be used if the radio box is selected.</p></td>
</tr>
<tr>
<td class="ts">4</td>
<td>
<p><b>checked</b></p>
<p>Set to <i>checked</i> if you want to select it by default.</p>
</td>
</tr>
</table>
<h2>Select Box Control</h2>
<p>A select box, also called drop down box which provides option to list down various options in the form of drop down list, from where a user can select one or more options.</p>
<h3>Example</h3>
<p>Here is example HTML code for a form with one drop down box</p>
<pre style="background-color:azure; class="prettyprint notranslate">
<!DOCTYPE html>
<html>
<head>
<title>Select Box Control</title>
</head>
<body>
<form>
<select name = "dropdown">
<option value = "Maths" selected>Maths</option>
<option value = "Physics">Physics</option>
</select>
</form>
</body>
</html>
</pre>
</div>
<a target="_blank" href="f12-6.html" class="w3-btn w3-margin-bottom"><button style="background-color:rgb(115, 126, 226);">Try it Yourself</button> »</a>
</div>
<h2>Attributes</h2>
<p>Following is the list of important attributes of <select> tag −</p>
<table class="table table-bordered">
<tr>
<th>Sr.No</th>
<th style="text-align:center;">Attribute & Description</th>
</tr>
<tr>
<td class="ts">1</td>
<td>
<p><b>name</b></p>
<p>Used to give a name to the control which is sent to the server to be recognized and get the value.</p>
</td>
</tr>
<tr>
<td class="ts">2</td>
<td>
<p><b>size</b></p>
<p>This can be used to present a scrolling list box.</p>
</td>
</tr>
<tr>
<td class="ts">3</td>
<td>
<p><b>multiple</b></p>
<p>If set to "multiple" then allows a user to select multiple items from the menu.</p>
</td>
</tr>
</table>
<p>Following is the list of important attributes of <option> tag −</p>
<table class="table table-bordered">
<tr>
<th>Sr.No</th>
<th style="text-align:center;">Attribute & Description</th>
</tr>
<tr>
<td class="ts">1</td>
<td>
<p><b>value</b></p>
<p>The value that will be used if an option in the select box box is selected.</p>
</td>
</tr>
<tr>
<td class="ts">2</td>
<td>
<p><b>selected</b></p>
<p>Specifies that this option should be the initially selected value when the page loads.</p>
</td>
</tr>
<tr>
<td class="ts">3</td>
<td>
<p><b>label</b></p>
<p>An alternative way of labeling options</p>
</td>
</tr>
</table>
<h2>File Upload Box</h2>
<p>If you want to allow a user to upload a file to your web site, you will need to use a file upload box, also known as a file select box. This is also created using the <input> element but type attribute is set to <b>file</b>.</p>
<h3>Example</h3>
<p>Here is example HTML code for a form with one file upload box −</p>
<pre style="background-color:azure; class="prettyprint notranslate">
<!DOCTYPE html>
<html>
<head>
<title>File Upload Box</title>
</head>
<body>
<form>
<input type = "file" name = "fileupload" accept = "image/*" />
</form>
</body>
</html>
</pre>
</div>
<a target="_blank" href="f12-7.html" class="w3-btn w3-margin-bottom"><button style="background-color:rgb(115, 126, 226);">Try it Yourself</button> »</a>
</div>
<h2>Attributes</h2>
<p>Following is the list of important attributes of file upload box −</p>
<table class="table table-bordered">
<tr>
<th>Sr.No</th>
<th style="text-align:center;">Attribute & Description</th>
</tr>
<tr>
<td class="ts">1</td>
<td>
<p><b>name</b></p>
<p>Used to give a name to the control which is sent to the server to be recognized and get the value.</p>
</td>
</tr>
<tr>
<td class="ts">2</td>
<td>
<p><b>accept</b></p>
<p>Specifies the types of files that the server accepts.</p>
</td>
</tr>
</table>
<h2>Button Controls</h2>
<p>There are various ways in HTML to create clickable buttons. You can also create a clickable button using <input>tag by setting its type attribute to <b>button</b>. The type attribute can take the following values −</p>
<table class="table table-bordered">
<tr>
<th>Sr.No</th>
<th style="text-align:center;">Type & Description</th>
</tr>
<tr>
<td class="ts">1</td>
<td>
<p><b>submit</b></p>
<p>This creates a button that automatically submits a form.</p>
</td>
</tr>
<tr>
<td class="ts">2</td>
<td>
<p><b>reset</b></p>
<p>This creates a button that automatically resets form controls to their initial values.</p>
</td>
</tr>
<tr>
<td class="ts">3</td>
<td>
<p><b>button</b></p>
<p>This creates a button that is used to trigger a client-side script when the user clicks that button.</p>
</td>
</tr>
<tr>
<td class="ts">4</td>
<td>
<p><b>image</b></p>
<p>This creates a clickable button but we can use an image as background of the button.</p>
</td>
</tr>
</table>
<h3>Example</h3>
<p>Here is example HTML code for a form with three types of buttons −</p>
<pre style="background-color:azure; class="prettyprint notranslate">
<!DOCTYPE html>
<html>
<head>
<title>File Upload Box</title>
</head>
<body>
<form>
<input type = "submit" name = "submit" value = "Submit" />
<input type = "reset" name = "reset" value = "Reset" />
<input type = "button" name = "ok" value = "OK" />
<input type = "image" name = "imagebutton" src = "/html/images/logo.png" />
</form>
</body>
</html>
</pre>
</div>
<a target="_blank" href="f12-8.html" class="w3-btn w3-margin-bottom"><button style="background-color:rgb(115, 126, 226);">Try it Yourself</button> »</a>
</div>
<h2>Hidden Form Controls</h2>
<p>Hidden form controls are used to hide data inside the page which later on can be pushed to the server. This control hides inside the code and does not appear on the actual page. For example, following hidden form is being used to keep current page number. When a user will click next page then the value of hidden control will be sent to the web server and there it will decide which page will be displayed next based on the passed current page.</p>
<h3>Example</h3>
<p>Here is example HTML code to show the usage of hidden control −</p>
<pre style="background-color:azure; class="prettyprint notranslate">
<!DOCTYPE html>
<html>
<head>
<title>File Upload Box</title>
</head>
<body>
<form>
<p>This is page 10</p>
<input type = "hidden" name = "pagename" value = "10" />
<input type = "submit" name = "submit" value = "Submit" />
<input type = "reset" name = "reset" value = "Reset" />
</form>
</body>
</html>
</pre>
</div>
<a target="_blank" href="f12-9.html" class="w3-btn w3-margin-bottom"><button style="background-color:rgb(115, 126, 226);">Try it Yourself</button> »</a>
</div>
</body>
</html>