-
Notifications
You must be signed in to change notification settings - Fork 0
/
JsBasics.html
173 lines (139 loc) · 4.52 KB
/
JsBasics.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
<!-- To find maximum from 3 input values -->
<html>
<head>
<title> maximum of 3 numbers </title>
<script>
let n1, n2, n3;
n1 = parseInt(window.prompt("Enter n1 value"));
n2 = parseInt(window.prompt("Enter n2 value"));
n3 = parseInt(window.prompt("Enter n3 value"));
if(n1 >n2 && n1 > n3) document.writeIn("maximum is" + n1);
else if (n2 > n1 && n2 > n3) document.writeIn("maximum is" + n2);
else document.writeIn("maximum is" + n3);
</script>
</head>
<body>
</body>
</html>
<!-- to find factorial -->
<html>
<head>
<title> Factorial </title>
<script>
let n, i, fact = 1;
n = parseInt(window.prompt("Enter a number"));
if(n===0) document.writeIn("Factorial is 1");
else {
for(i=1; i <=n ; i++) {
fact = fact * i;
}
document.writeIn('factorail is ' + fact);
}
</script>
</head>
<body>
</body>
</html>
<!-- to get the square and cube of a number -->
<html>
<head>
<script>
let a;
a = parseInt(window.prompt('Enter a number'));
document.writeIn('Square of given number is' + sqaure(a));
document.writeIn('Cube of given number is' + cube(a));
function square(k) {
let s;
s = k * k;
return s;
}
fucntion cube(m) {
let n;
n = m * m * m;
return n;
}
</script>
</head>
<body>
</body>
</html>
<!-- Validation in Js -->
<html>
<head>
<title> Validation In Simple JS using .forms</title>
<script>
function validate() {
let email,uName, pWord, cpWord ;
email = document.forms('form').email.value;
uName = document.forms('form').uName.value;
pWord = document.forms('form').pWord.value;
cpWord = document.forms('form').cpWord.value;
if(email === '' || cpWord === '' || pWord === '' || uName === '') alert('Enter the input fields');
else if(uName.length < 8) alert('Username must be atleast 8 characters long without spacing');
else if(pWord.length < 6) alert('Password must be strong with alphanumeric character and atleast 7 charater long without spacing');
else if(cpWord !== pWord) alert('Password does not match, please enter the password carefully');
else alert('Form successfully filled');
}
</script>
</head>
<body>
<form name='form'>
<table align='center'>
<tr>
<td> Username: </td>
</tr>
<tr>
<td> Password: </td>
</tr>
<tr>
<td> confirm Password: </td>
</tr>
<tr>
<td> Email: </td>
<td> <input type='text' name='email'></input> </td>
</tr>
<tr>
<td colspan=2 align='center'> <input type='button' onclick='validate()' name='btn' value='submit' /> </td>
</tr>
</table>
</form>
</body>
</html>
<!-- Event Handling -->
<html>
<head>
<title> Event Handling </title>
<body onload='alert("Example for JS Events")'>
<h1 align='center'> JS Events </h1>
<br/> <hr/>
<form name='form' onSubmit='alert("submit")'>
<!-- onBlur Event: -->
<input type='text' value='Click Here' onBlur='alert("Not Clear")' />
<!-- onClick Event -->
<input type='text' value='Click Here' onClick='alert("Changed")' />
<br/>
<!-- onDoubleClick -->
<input type='text' value='Click Here' onDblClick='alert("Double Clicked")' />
<!-- onMouseMove Event -->
<input type='button' value='Place Here' onMouseMove='alert("Mouse Moved to this Place")' />
<!-- onKeyUp Event -->
<input type='text' value='press any key' onKeyUp='alert("KeyUp Pressed")' />
<!-- onKeyDown Event -->
<input type='text' value='press any key' onKeyDown='alert("KeyDown Pressed")' />
<!-- OnSUbmit Event -->
<input type='Submit' value='Submit'> </input>
</form>
</body>
</html>
<!-- Window Methods -->
<html>
<head>
<title> Window Operations </title>
</head>
<body>
<form>
<input type="button" value='New Window' onClick= "window.open('login.html)", "login" , width= 250, height= 200)></input>
<input type='button' value='close' onClick='window.close()'> </input>
</form>
</body>
</html>