Web Programming Notes
Web Programming Notes
SCRIPTING:
Scripting allows you to turn a simple, static HTML page into a more
dynamic page. It makes it possible for users to interact with a website rather than
just look at the pages.
1
SCRIPTING
JavaScript is template based not class based. Here, we don't create class to get the
object. But, we direct create objects.
Example program
<html>
<body>
2
SCRIPTING
<h2>JavaScript Objects</h2>
<p>Creating an object:</p>
<p id="demo"></p>
<script>
const person = {
firstName : "John",
lastName : "Doe",
age : 50,
eyeColor : "blue"
};
document.getElementById("demo").innerHTML = person.firstName + " " +
person.lastName;
</script>
</body>
</html>
Output:
JavaScript Objects
Creating an object:
John Doe
The general rules for constructing names for variables (unique identifiers)
are:
3
SCRIPTING
Names can also begin with $ and _ (but we will not use it in this
tutorial).
Names are case sensitive (y and Y are different variables).
Reserved words (like JavaScript keywords) cannot be used as names.
JavaScript Literals are the fixed value that cannot be changed, you do not need to
specify any type of keyword to write literals. Literals are often used to initialize
variables in programming, names of variables are string literals.
Numeric Literal
Floating-Point Literal
Boolean Literal
String Literal
Array Literal
Regular Expression Literal
Object Literal
Numerical literals
4
SCRIPTING
A string literal is a combination of zero or more characters enclosed within a single( ')
or double quotation marks (").
5
SCRIPTING
Arithmetic Operators
Comparison(Realtional) Operators
Bitwise operator
Logical Operators
Assignment operators
Special operators
+ Addition 10+20 = 30
- Subtraction 20-10 = 10
/ Division 20/10 = 2
6
SCRIPTING
7
SCRIPTING
= Assign 10+10 = 20
8
SCRIPTING
Operator Description
(?:) Conditional Operator returns value based on the condition. It is like if-else.
JavaScript Expressions
An expression is a combination of values, variables, and operators, which
computes to a value.
<html>
<body>
<h2>JavaScript Expressions</h2>
<p id="demo"></p>
<script>
var x;
9
SCRIPTING
x = 5;
document.getElementById("demo").innerHTML = x * 10;
</script>
</body>
</html>
Output
JavaScript Expressions
Expressions compute to values.
50
JAVASCRIPT STATEMENTS
This statement tells the browser to write "Hello Dolly." inside an HTML
element with id="demo"
<html>
<body>
<h2>JavaScript Statements</h2>
<p>In HTML, JavaScript statements are executed by the browser.</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = "Hello Dolly.";
</script>
10
SCRIPTING
</body>
</html>
OUTPUT
JavaScript Statements
In HTML, JavaScript statements are executed by the browser.
Hello Dolly.
Features of Javascript
Scripting
Interpreter
Event Handling
Light Weight
Case Sensitive
Control Statements
Javascript has control statements like if-else-if, switch case, and loop. Users can
write complex code using these control statements.
11
SCRIPTING
Dynamic Typing
Javascript variables can have any value type. The same variable can have a
string value, an integer value, or any other.
Client-side Validations
Javascript client-side validations allow users to submit valid data to the server
during a form submission.
Platform Independent
Javascript will run in the same way in all systems with any operating system.
JavaScript Events
The change in the state of an object is known as an Event. In html, there are various
events which represents that some activity is performed by the user or by the browser.
When javascript code is included in HTML, js react over these events and allow the
execution. This process of reacting over the events is called Event Handling
Mouse events:
mouseover onmouseover When the cursor of the mouse comes over the
12
SCRIPTING
Keyboard events:
Keydown & Keyup onkeydown & onkeyup When the user press and then release the key
Form events:
Change onchange When the user modifies or changes the value of a form element
Window/Document events
Load onload When the browser finishes the loading of the page
Unload onunload When the visitor leaves the current webpage, the browser unloads
Resize onresize When the visitor resizes the window of the browser
13
SCRIPTING
function clickevent()
{
document.write("This is JavaTpoint");
}
</script>
<form>
<input type="button" onclick="clickevent()" value="Who's this?"/>
</form>
</body>
output
JavaScript Events
[who is this?]
MouseOver Event
<html>
<head>
<h1> Javascript Events </h1>
</head>
<body>
<script language="Javascript" type="text/Javascript">
function mouseoverevent()
{
alert("This is JavaTpoint");
}
</script>
<p onmouseover="mouseoverevent()"> Keep cursor over me</p>
</body>
</html>
14
SCRIPTING
output
Javascript Events
Keep cursor over me
(if you keep cursor on keep cursor over me we get the msg as This is java
Tpoint)
Keydown Event
<html>
<head> Javascript Events</head>
<body>
<h2> Enter something here</h2>
<input type="text" id="input1" onkeydown="keydownevent()"/>
<script>
function keydownevent()
{
document.getElementById("input1");
alert("Pressed a key");
}
</script>
</body>
</html>
Output
JavaScript Events
Enter something here
If we try to enter text into textbox we will get the msg as [Pressed a key]
JAVASCRIPT WINDOWS
Window is the object of browser, it is not the object of javascript.
15
SCRIPTING
Method Description
confirm() displays the confirm dialog box containing message with ok and cancel button.
setTimeout() performs action after specified time like calling function, evaluating expressions
etc.
1. <script type="text/javascript">
2. function msg(){
3. alert("Hello Alert Box");
4. }
5. </script>
6. <input type="button" value="click" onclick="msg()"/>
Output of the above example
[click]
If we click on the button click we will get the dialog box with the message as
Hello alert box and ok button
Example of confirm() in javascript
It displays the confirm dialog box. It has message with ok and cancel buttons.
1. <script type="text/javascript">
2. function msg(){
3. var v= confirm("Are u sure?");
4. if(v==true){
5. alert("ok");
6. }
7. else{
16
SCRIPTING
8. alert("cancel");
9. }
10.
11. }
12. </script>
13.
14. <input type="button" value="delete record" onclick="msg()"/>
Output of the above example
[delete record]
If we click on delete record button we will get the dialog box as “Are u sure?”
message with ok and cancel buttons
It displays prompt dialog box for input. It has message and textfield.
1. <script type="text/javascript">
2. function msg(){
3. var v= prompt("Who are you?");
4. alert("I am "+v);
5.
6. }
7. </script>
8.
9. <input type="button" value="click" onclick="msg()"/>
1. <script type="text/javascript">
2. function msg(){
17
SCRIPTING
3. open("http://www.vmtw.in/);
4. }
5. </script>
6. <input type="button" value="javatpoint" onclick="msg()"/>
Output of the above example
[javatpoint]
If we click on button javatpoint we redirect to vmtw page
1. <script type="text/javascript">
2. function msg(){
3. setTimeout(
4. function(){
5. alert("Welcome to Javatpoint after 2 seconds")
6. },2000);
7.
8. }
9. </script>
10.
11. <input type="button" value="click" onclick="msg()"/>
Output of the above example
[click]
If we click on click button we get the dialog box as welcome to javatpoint after 2
seconds.
DOCUMENTS
The document object represents the whole html document.
element that represents the html document. It has properties and methods. By the
help of
18
SCRIPTING
Method Description
writeln("string") writes the given string on the doucment with newline character
getElementsByName() returns all the elements having the given name value.
19
SCRIPTING
getElementsByTagName() returns all the elements having the given tag name.
getElementsByClassName() returns all the elements having the given class name.
<html>
<head>
<title>document.write Example</title>
</head>
<body>
<script type="text/javascript">
document.write("Hello,");
</script>
</body>
</html>
<head>
<title>document.writeln Example</title>
</head>
<body>
<script type="text/javascript">
document.writeln("Hello,");
</script>
20
SCRIPTING
</body>
</html>
Ouput: hello,
This is a example using document.writeln().
getElementById()
<html>
<head>
<body>
</script>
<body>
</html>
getElementsByName()
The document.getElementsByName() method returns all the element of specified name.
<html>
<head> <title> getElementsByName</title></head>
<body>
<div name=”special”>
<h2>This is heading</h2>
<p>This is paragraph</p>
21
SCRIPTING
</div>
<script>
Let x=document.getElementByName(“special)
Document.write(x)
</script>
</body>
</html>
Output:
This is heading
This is paragraph
<h2>This is heading</h2>
<p>This is paragraph</p>
</div>
<div>
<h2>This is heading</h2>
<p>This is paragraph</p>
</div>
<script>
Let x=document.getElementByClassName(“special)
Document.write(x)
</script>
</body>
</html>
22
SCRIPTING
Output:
This is heading
This is paragraph
This is heading
This is paragraph
getElementsByTagName()
It returns all the elements having the given tag name
<html>
<head> <title> getElementsByTagName</title></head>
<body>
<div name=”special”>
<h2>This is heading</h2>
<p>This is paragraph</p>
</div>
<div>
<h2>This is heading</h2>
<p>This is paragraph</p>
</div>
<script>
Let x=document.getElementByTagName(h2))
Document.write(x)
</script>
</body>
</html>
23
SCRIPTING
FRAMES
Frames in HTML are used to divide your browser window into more than one
section in which every phase can load a separate HTML report and a group of
frames within the browser window is referred to as a frameset.
<html>
<body>
<frameset cols="*,*,*">
<frame src="frame1.html">
<frame src="frame2.html">
<frame src="frame3.html">
</frameset>
</body>
</html>
OUTPUT:
<body>
<frameset rows="*,*,*">
<frame src="frame1.html">
<frame src="frame2.html">
<frame src="frame3.html">
</frameset>
</body>
</html>
24
SCRIPTING
OUTPUT:
DATATYPES
JavaScript is a dynamic type language, means you don't need to specify type of the variable
because it is dynamically used by JavaScript engine. You need to use var here to specify the
data type. It can hold any type of values such as numbers, strings etc.
25
SCRIPTING
<html>
<body>
<script>
Var a,b,c;
A=10;
B=3.14;
C=”students”;
Var d=true;
</script>
</body>
26
SCRIPTING
</html>
BUILTIN FUNCTIONS
Like any other scripting language Javascript also has its own built in functions. These built in
functions also known as global functions.
you can use these function with any Javascript built in object such as String , Number, Date,
RegExp, Array, Boolean and Math. Javascript's all built in object support these functions.
ISNaN(): predefined global function in JavaScript and it is used to check whether a given value
is an illegible number or not
ISNaN():
<html>
<head>
<title>JavaScipt Example</title>
</head>
<body>
<script>
var num1 = 10;
var num2 = parseInt("Hello");
document.write("num1: " + num1 + "<br>");
document.write("num2: " + num2 + "<br>");
//checking illegal value using isNaN() function
if(isNaN(num1))
document.write("num1 is an illegal number <br>");
else
document.write("num1 is a legal number <br>");
if(isNaN(num2))
document.write("num2 is an illegal number <br>");
else
document.write("num2 is a legal number <br>");
27
SCRIPTING
</script>
</body>
</html>
output: num1: 10
num2: NaN
num1 is a legal number
num2 is an illegal number
eval() function:
<html>
<head>
<title>JavaScipt Example</title>
</head>
<body>
<script>
var num1 = 100;
var num2 = 200;
var num3 = eval("num1 + num2"); //add num1 and num2
var num4 = eval("num3 + 100"); //add num3 and 100
document.write("num3: " + num3 + "<br>");
document.write("num4: " + num4 + "<br>");
</script>
</body>
</html>
Output:
num3: 300
num4: 400
parseInt():
<html>
<head><title>parseint function</title></head>
<script>
var str1 = "123"; //decoimal string
var str2 = "12.23"; //float string
var str3 = "123 456 789" //multiple Numbers
var str4 = " 123 "; //string contains leading & trailing spaces
var str5 = "123456 is my password"; //string contains Number in
28
SCRIPTING
starting
var str6= "My password is 123456"; //string contains Number in
ending
//parsing & pritning the values
document.write("Number value of str1: " + parseInt(str1) + "<br>");
document.write("Number value of str2: " + parseInt(str2) + "<br>");
document.write("Number value of str3: " + parseInt(str3) + "<br>");
document.write("Number value of str4: " + parseInt(str4) + "<br>");
document.write("Number value of str7: " + parseInt(str5) + "<br>");
document.write("Number value of str8: " + parseInt(str6) + "<br>");
</script>
output
Number value of str1: 123
Number value of str2: 12
Number value of str3: 123
Number value of str4: 123
Number value of str5: 123456
Number value of str6: NaN
Number() function:
<html>
<head>
<title>JavaScipt Example</title>
</head>
<body>
<script>
var a = "10";
var b = "10 20";
var c = "1234 Hello";
var d = "Hello 1234";
var e = true;
//converting values to number using Number() function
document.write("Number(a) = " + Number(a) + "<br>");
document.write("Number(b) = " + Number(b) + "<br>");
document.write("Number(c) = " + Number(c) + "<br>");
document.write("Number(d) = " + Number(d) + "<br>");
document.write("Number(e) = " + Number(e) + "<br>");
</script>
29
SCRIPTING
</body>
</html>
Out put:
Number(a) = 10
Number(b) = NaN
Number(c) = NaN
Number(d) = NaN
Number(e) = 1
String() function:
<title>JavaScipt Example</title>
</head>
<body>
<script>
var a = "10";
var b = "10 20";
var c = "1234 Hello";
var d = "Hello 1234";
var e = true;
var f = new Date();
//converting values to string using String() function
document.write("String(a) = " + String(a) + "<br>");
document.write("String(b) = " + String(b) + "<br>");
document.write("String(c) = " + String(c) + "<br>");
document.write("String(d) = " + String(d) + "<br>");
document.write("String(e) = " + String(e) + "<br>");
document.write("String(f) = " + String(f) + "<br>");
</script>
</body>
</html>
Output:
String(a) = 10
String(b) = 10 20
String(c) = 1234 Hello
String(d) = Hello 1234
String(e) = true
String(f) = Sat Feb 02 2019 23:03:12 GMT+0530 (India Standard Time)
30
SCRIPTING
The default object of browser is window means you can call all the functions of window by
specifying window or directly. For example:
window.alert("hello javatpoint");
is same as
alet(“hello javapoint”);
Even the document object (of the HTML DOM) is a property of the window
object
If you want to access any element in an HTML page, you always start with
accessing the document object.
History:
he history object contains the URLs visited by the user (in the browser
window).
screen:
31
SCRIPTING
navigator object :
location:
veritfing forms
It is important to validate the form submitted by the user because it can have
inappropriate values. So, validation is must to authenticate user.
JavaScript provides facility to validate the form on the client-side so data processing
will be faster than server-side validation. Most of the web developers prefer JavaScript
form validation.
Through JavaScript, we can validate name, password, email, date, mobile numbers and
more fields.
In this example, we are going to validate the name and password. The name can’t be empty
and password can’t be less than 6 characters long.
1. <script>
2. function validateform(){
3. var name=document.getElementByid(“name”);
4. var password=document.getElementByid(“password”);
5.
6. if (name==null || name==""){
7. alert("Name can't be blank");
8. return false;
32
SCRIPTING
9. }else if(password.length<6){
10. alert("Password must be at least 6 characters long.");
11. return false;
12. }
13. }
14. </script>
15. <body>
16. <form name="myform" method="post" action="abc.jsp" onsubmit="return v
alidateform()" >
17. Name: <input type="text" name="name"><br/>
18. Password: <input type="password" name="password"><br/>
19. <input type="submit" value="register">
20. </form>
Output:
Name: [ ]
Password: [ ]
[submit]
HTML5
33
SCRIPTING
34
SCRIPTING
35
SCRIPTING
Advanced Animations.
Rounded Corners
Text and Box Shadows.
HTML Canvas
There are many types of tools available that web designers can use, such as
1. Wix: Wix is a website-building tool that does not require coding to build websites. If
you want to build a website but do not have a lot of experience in it, Wix could be one
of the best options.
36
SCRIPTING
2. Squarespace : Squarespace is another website-building tool that offers more than 100
website templates to start with
3. Shopify: Shopify is a digital storefront platform that helps businesses create their
digital stores.
4. WordPress: WordPress is the most known Content Management System (CMS) that
can help you build a website quickly.
5. Webflow: Webflow is another website designer tool that doesn’t require coding to
build websites. If you don’t want to get involved in coding, Webflow is one of the
tremendous website-building platforms. Also, you can add site elements using the
drag-and-drop feature to make a customized design layout.
6. Adobe Dreamweaver: Adobe Dreamweaver is a commercial coding engine that allows
you to view a real-time preview of the updated content as soon as you edit the code.
7. Figma: Figma is an online web designing tool that enables users to edit and
prototype website designs. This tool empowers the collaborative effort of the web
designing team. You can collaborate in brainstorming ideas and create prototypes and
share them with other collaborators for feedback using the same tool.
8. Nova: Nova is an updated version of Panic, a website development application used
for the Mac Operating System. This website layout design tool aims to reduce the
number of secondary tools needed to develop a web application like CSS editor, FTP
client, and version control system. This, in turn, improves the workflow and
functionality of your development team.
9. Google Web Designer: Google Web Designer is a website designing platform that
helps build interactive and appealing webpage designs based on HTML 5. The tool
also ensures that the webpage designs and motion graphics are running as expected
and can be viewed on various digital devices like computers and smartphones.
10. Adobe XD: Canva is the most popular design platform. This tool can help you to
create visuals for your website
11. InVision Studio: One of the most critical steps in website designing is prototyping.
These prototypes act as a temple for the real website. Adobe XD is a vector-based
prototyping tool that enables users to visualize their designs and evaluate the user
experience.
37
SCRIPTING
<html>
<head><title> syudents</title>
</head>
<body>
<img src=https://www.washingtonpost.com/rf/image_1484w/2010-
2019/WashingtonPost/2015/07/27/Obituaries/Images/04863016-
784.jpg?t=20170517style="display: width="500" height="600">
<P>some of queots of him</p>
</body>
</html>
Queots page:
<html>
<body>
<h1>“Dream is not that which you see while sleeping it is something that does
not let you sleep.”</h1>
<h2>"Look at the sky. We are not alone. The whole universe is friendly to us
and conspires only to give the best to those who dream and work." </h2>
<h1>"If you want to shine like a sun, first burn like a sun." </h1>
<h3>"To succeed in your mission, you must have single-minded devotion to
your goal."</h3>
<h1>"If four things are followed - having a great aim, acquiring knowledge,
hard work, and perseverance - then anything can be achieved."</h1>
<p>"Climbing to the top demands strength, whether it is to the top of Mount
Everest or to the top of your career."</p>
<h2>"Don't take rest after your first victory because if you fail in second, more
lips are waiting to say that your first victory was just luck."</h2>
38
SCRIPTING
<h3>"To become 'unique,' the challenge is to fight the hardest battle which
anyone can imagine until you reach your destination."</h3>
<h2>"Never stop fighting until you arrive at your destined place - the unique
you. Have an aim in life, continuously acquire knowledge, work hard, and have
perseverance to realise the great life."</h2>
<ul>
<li>“Determination is the power that sees us through all our frustrations and
obstacles. It helps us in building our willpower which is the very basis of
success.” </li>
<li>“A big shot is a little shot who keeps on shooting, so keep trying.”― A.P.J.
Abdul Kalam, Wings of Fire</li>
<li>“The country doesn't deserve anything less than success from us. Let us aim
for success".” ― A.P.J. Abdul Kalam, Wings of Fire</li></ul>
<ol><li>“Great dreams of great dreamers are always transcended.” ― Dr. A.P.J.
Abdul Kalam</li>
<li>“Be more dedicated to making solid achievements than in running after
swift but synthetic happiness,” ― A.P.J. Abdul Kalam, Wings of Fire</li>
<li>“To succeed in life and achieve results, you must understand and master
three mighty forces— desire, belief, and expectation." Iyadurai” ― A.P.J. Abdul
Kalam, Wings of Fire</li>
<li>“I reminded myself that the best way to win was to not need to win. The
best performances are accomplished when you are relaxed and free of doubt. I”
― A.P.J. Abdul Kalam, Wings of Fire</li>
<li>“it does not matter how large or small your sphere of activity is, what
counts finally is the commitment that you bring to the job that has been
ordained for you in this life.” ― A.P.J. Abdul Kalam, My Journey: Transforming
Dreams into Actions</li></ol>
</body>
</html>
Output:
39
SCRIPTING
visit queots0
40
SCRIPTING
41