-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJs-Form-Events.html
More file actions
79 lines (77 loc) · 2.19 KB
/
Js-Form-Events.html
File metadata and controls
79 lines (77 loc) · 2.19 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style>
* {
text-align: center;
}
</style>
<title>Form Events</title>
</head>
<body>
<form action="" onsubmit="submitFunction()">
<label for="">Name </label
><input
type="text"
value="Yahoo Baba"
id="fname"
onfocus="focusFunction(this)"
onblur="blurFunction(this)"
onchange="changeFunction(this)"
onselect="selectFunction()"
oninvalid="alert('please enter the name')";
required
/><br /><br />
<label for="">Class </label
><input
type="email"
id=""
onfocus="focusFunction(this)"
onblur="blurFunction(this)"
required
/><br /><br />
<label for="">Country </label
><select
id=""
onfocus="focusFunction(this)"
onblur="blurFunction(this)"
onchange="changeFunction(this)"
>
<option value="India">India</option>
<option value="Pakistan">Pakistan</option>
<option value="Bangladesh">Bangladesh</option>
<option value="China">China</option></select
><input type="submit" />
<br />
</form>
<div id="test" style="border: 1px solid red"></div>
<script>
// function focusFunction(){
// document.getElementById("fname").style.background = "lime";
function focusFunction(element) {
element.style.background = "lime";
}
function blurFunction(element) {
element.style.background = "";
}
function inputFunction() {
var x = element.value;
document.getElementById("test").innerHTML = x;
}
function changeFunction(element) {
var x = element.value;
document.getElementById("test").innerHTML = x;
}
function selectFunction() {
console.log("You selected some text.");
}
function submitFunction() {
var x = document.getElementById("fname").value;
alert("Hello " + x);
}
</script>
</body>
</html>