- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsBasics.html
More file actions
Latest commit
173 lines (139 loc) · 4.52 KB
/
Copy pathJsBasics.html
File metadata and controls
173 lines (139 loc) · 4.52 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
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>
letn1,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);
elseif(n2>n1&&n2>n3)document.writeIn("maximum is"+n2);
elsedocument.writeIn("maximum is"+n3);
</script>
</head>
<body>
</body>
</html>
<!-- to find factorial -->
<html>
<head>
<title> Factorial </title>
<script>
letn,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>
leta;
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));
functionsquare(k){
lets;
s=k*k;
returns;
}
fucntioncube(m){
letn;
n=m*m*m;
returnn;
}
</script>
</head>
<body>
</body>
</html>
<!-- Validation in Js -->
<html>
<head>
<title> Validation In Simple JS using .forms</title>
<script>
functionvalidate(){
letemail,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');
elseif(uName.length<8)alert('Username must be atleast 8 characters long without spacing');
elseif(pWord.length<6)alert('Password must be strong with alphanumeric character and atleast 7 charater long without spacing');
elseif(cpWord!==pWord)alert('Password does not match, please enter the password carefully');
elsealert('Form successfully filled');
}
</script>
</head>
<body>
<formname='form'>
<tablealign='center'>
<tr>
<td> Username: </td>
</tr>
<tr>
<td> Password: </td>
</tr>
<tr>
<td> confirm Password: </td>
</tr>
<tr>
<td> Email: </td>
<td><inputtype='text' name='email'></input></td>
</tr>
<tr>
<tdcolspan=2align='center'><inputtype='button' onclick='validate()' name='btn' value='submit' /></td>
</tr>
</table>
</form>
</body>
</html>
<!-- Event Handling -->
<html>
<head>
<title> Event Handling </title>
<bodyonload='alert("Example for JS Events")'>
<h1align='center'> JS Events </h1>
<br/><hr/>
<formname='form' onSubmit='alert("submit")'>
<!-- onBlur Event: -->
<inputtype='text' value='Click Here' onBlur='alert("Not Clear")' />
<!-- onClick Event -->
<inputtype='text' value='Click Here' onClick='alert("Changed")' />
<br/>
<!-- onDoubleClick -->
<inputtype='text' value='Click Here' onDblClick='alert("Double Clicked")' />
<!-- onMouseMove Event -->
<inputtype='button' value='Place Here' onMouseMove='alert("Mouse Moved to this Place")' />
<!-- onKeyUp Event -->
<inputtype='text' value='press any key' onKeyUp='alert("KeyUp Pressed")' />
<!-- onKeyDown Event -->
<inputtype='text' value='press any key' onKeyDown='alert("KeyDown Pressed")' />
<!-- OnSUbmit Event -->
<inputtype='Submit' value='Submit'></input>
</form>
</body>
</html>
<!-- Window Methods -->
<html>
<head>
<title> Window Operations </title>
</head>
<body>
<form>
<inputtype="button" value='New Window' onClick= "window.open('login.html)", "login" , width= 250,height= 200)></input>
<inputtype='button' value='close' onClick='window.close()'></input>
</form>
</body>
</html>