forked from 4iz268/cviceni
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10-js-form-fields.html
75 lines (35 loc) · 961 Bytes
/
10-js-form-fields.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>JS form fields</title>
</head>
<body>
<h1>JS form fields</h1>
<input type="button" onclick="fillForm()" value="Fill the form!">
<form id="myForm">
<label for='first'>First Name</label>
<input type="text" id="first">
<br/><br/>
<label for='last'>Last Name</label>
<input type="text" id="last">
<br/><br/>
<label for='rock'>Wanna rock?</label>
<input type="checkbox" id="rock">
<br/><br/>
<input type="submit">
<input type="reset" onclick="return confirmReset()">
</form>
<script>
function fillForm() {
var form = document.getElementById('myForm').elements;
form.namedItem('first').value = 'John';
form.namedItem('last').value = 'Doe';
form.namedItem('rock').checked = true;
}
function confirmReset(){
return confirm('Do you want to reset the form?');
}
</script>
</body>
</html>