-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformevent.html
More file actions
88 lines (71 loc) · 2.22 KB
/
formevent.html
File metadata and controls
88 lines (71 loc) · 2.22 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
80
81
82
83
84
85
86
87
88
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>keyboard events</title>
<script
src="https://code.jquery.com/jquery-3.7.1.min.js"
integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo="
crossorigin="anonymous"
></script>
<style>
#test_box {
border: 1px solid royalblue;
margin-top: 20px;
padding: 20px;
}
</style>
</head>
<body>
<h1>Form Events</h1>
<form action="" id="sform">
<label for="">Name</label>
<input type="text" name="name" id="sname" /><br /><br />
<label for="">Class</label>
<input type="text" name="sclass" id="sclass" /><br /><br />
<label for="">Country</label>
<select id="scountry">
<option value="india">India</option>
<option value="russia">russia</option>
<option value="japan">Japan</option></select
><br /><br />
<input id="submit" type="submit" name="submit" value="submit" />
</form>
<div id="test_box"><!-- empty div --></div>
<!-- here i stated jquery code -->
<script>
$(document).ready(function () {
//this is for focus ()
$("#sname,#sclass,#scountry").focus(function(){
$(this).css("background-color", "cyan");
});
//this is for blur()
$("#sname,#sclass,#scountry").blur(function(){
$(this).css("background-color", "lime");
});
//this is for change()
$("#scountry").change(function(){
// $(this).css("background-color", "yellow");
var a = $(this).val();
$("#test_box").html(a);
});
//this is for select()
$("#sname,#sclass").select(function(){
$(this).css("background-color", "red");
});
//this is for submit()
$("#sform").submit(function () {
alert("Form Submited");
});
//to check all value
$('#sform').submit(function(){
var name = $('#sname').val();
var classname = $('#sclass').val();
var country = $('#scountry').val();
alert("Hello " + name + " class " + classname + " Country " + scountry );
})
});
</script>
</body>
</html>