Unit - 3 JavaScript
Unit - 3 JavaScript
Semester: III
JavaScript is not Java. They are similar in some ways but fundamentally
different in others.
JavaScript Types
There’re 2 types:
Navigator’s JavaScript, also called client-side JavaScript
LiveWire JavaScript, also called server-side JavaScript
3
while statement:
while (condition) {
statements
}
10
11
12
13
15
if (condition) {
statements;
} else if (condition) {
statements;
} else {
statements;
}
JS
16
18
while (condition) {
statements;
} JS
do {
statements;
} while (condition);
JS
19
20
21
23
32
33
JS
35
36
37
39
There are two basic components of a Web form: the shell, the part that the
user fills out, and the script which processes the information
HTML tags are used to create the form shell. Using HTML you can create
text boxes, radio buttons, checkboxes, drop-down menus, and more...
40
Text Box
Drop-down Menu
Radio Buttons
Checkboxes
Text Area
41
Reset Button
BCA Web and Internet Technology
Submit Button Dr. Amita Gandhi
The Form Shell
42
43
44
The NAME attribute is used to identify the text box to the processing script
The VALUE attribute is used to specify the text that will initially appear in
the text box
The SIZE attribute is used to define the size of the box in characters
The MAXLENGTH attribute is used to define the maximum number of
characters that can be typed in the box
45
46
BCA
VALUE="Medium">Medium
Web and Internet Technology Dr. Amita Gandhi
Creating Checkboxes
<OPTION VALUE="PINEAPPLE">PINEAPPLE
BCA Web and Internet Technology Dr. Amita Gandhi
Creating a Submit Button
51
52
<!DOCTYPE html>
<html lang="en">
<head>
<title>JavaScript Form Demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div class="container">
<form action="signup.html" method="post" id="signup">
<h1>Sign Up</h1>
<div class="field">
<label for="name">Name:</label> 53
<small></small>
</div>
<div class="field">
<label for="email">Email:</label>
<input type="text" id="email" name="email" placeholder="Enter your email address" />
<small></small>
</div>
<div class="field">
<button type="submit" class="full">Subscribe</button>
</div>
</form>
</div>
<script src="js/app.js"></script> 54
</body>
BCA Web and Internet Technology Dr. Amita Gandhi
Form: Output
55
56
</script></body>
BCA Web and Internet Technology Dr. Amita Gandhi
document.write( )
Document.write: It is used for testing purpose.
Syntax
document.write()
58
</script>
BCA Web and Internet Technology Dr. Amita Gandhi
window.alert( )
window.alert(): It displays the content using an alert box.
Syntax
window.alert()
60
</script>
BCA Web and Internet Technology Dr. Amita Gandhi
console.log( )
console.log(): It is used for debugging purposes.
Syntax:
console.log()
62
console.log(10*2);
BCA Web and Internet Technology Dr. Amita Gandhi
window.prompt( )
window.prompt():- it Allows to take input from user.
Syntax :
window.prompt()
64
66
67
68
69
70
71
72
73
74
75
76
77
78
81