-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswitch_case.html
More file actions
113 lines (89 loc) · 3.65 KB
/
switch_case.html
File metadata and controls
113 lines (89 loc) · 3.65 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>demo</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<h3 onclick="getData(1)">1</h3>
<h3 onclick="getData(2)">2</h3>
<h3 onclick="getData(3)">3</h3>
<h3 onclick="getData(4)">4</h3>
<h3 onclick="getData(5)">5</h3>
<h3 onclick="getData(6)">6</h3>
<button onclick="getData()">Click</button>
<p id="nu"></p>
<script>
function getData(value){
switch(value) {
case 1 : document.getElementById('nu').innerHTML = document.getElementById('nu').innerHTML+ '<br/>' + 'Floor No. 1';
break;
case 2 : document.getElementById('nu').innerHTML = document.getElementById('nu').innerHTML+ '<br/>' + 'Floor No. 2';
break;
case 3 : document.getElementById('nu').innerHTML = document.getElementById('nu').innerHTML+ '<br/>' + 'Floor No. 3';
break;
case 4 : document.getElementById('nu').innerHTML = document.getElementById('nu').innerHTML+ '<br/>' + 'Floor No. 4';
break;
case 5 : document.getElementById('nu').innerHTML = document.getElementById('nu').innerHTML+ '<br/>' + 'Floor No. 5';
break;
case 6 : document.getElementById('nu').innerHTML = document.getElementById('nu').innerHTML+ '<br/>' + 'Floor No. 6';
break;
default : document.getElementById('nu').innerHTML = document.getElementById('nu').innerHTML+ '<br/>' + 'Ground Floor';
}
}
</script>
<form>
<input type="text" name="" value="" id="day" />
<input type="submit" name="" value="Submit" onclick="getData2()" />
</form>
<br/>
<script>
function getData2(){
var dayV = document.getElementById('day').value;
dayV = dayV.toLowerCase();
switch(dayV){
case 'sunday' :
case 'saturday' : document.write('Today is Weekend');
break;
case 'wednesday' :
case 'friday' :
case 'thursday' :
case 'tuesday' :
case 'monday' :
document.write('Today is Weekdays');
break;
default : document.write('please enter correct day');
}
}
</script>
<br/><br/>
<input type="text" name="" value="" id="val1" />
<input type="text" name="" value="" id="val2" />
<select id="opr">
<option value="Add">Add</option>
<option value="Subtract">Subtract</option>
<option value="Multiply">Multiply</option>
<option value="Divide">Divide</option>
</select>
<input type="submit" name="" value="Submit" onclick="operation()" />
<p id="ope"></p>
<script>
function operation(){
var v1 = parseInt(document.getElementById('val1').value);
var v2 = parseInt(document.getElementById('val2').value);
var o2 = document.getElementById('opr').value;
switch(o2){
case 'Add' : alert(v1 + v2);
break;
case 'Subtract' : document.write(v1 - v2);
break;
case 'Multiply' : console.log(v1 * v2);
break;
case 'Divide' : alert(v1 / v2);
break;
}
}
</script>
</body>
</html>