Web Design Basics: HTML, CSS, JavaScript
Web Design Basics: HTML, CSS, JavaScript
A site or website is a set of related web pages located under a single domain name, typically produced by a
single person or organization. For examples [Link], [Link], [Link], [Link] etc.
Web Application:
The applications which will provide services over the web are called web applications.
Eg: [Link], [Link] etc.
1) Front-End:
developers who are responsible for the look and feel of a site is called Front end developers.
Java Script:
JavaScript is a lightweight, cross-platform and interpreted scripting language.
The main objective of Java Script is to add functionality to the HTML Pages. ie to add dynamic nature to
the HTML Pages.
If the response is varied from time to time and person to person then it is considered as dynamic response.
Eg inbox page of gmail
Eg: welcome page of any internet banking. Etc.
2) Back End:
back-end” means the server, application and database that work behind the scenes to deliver information to
the user.
It is the technology used to decide what to show to the end user on the Front-End.
i.e. Backend is responsible to generate required response to the end user, which is displayed by the Front-
End.
In order to make the server, application, and database communicate with each other, back-end developers
uses server-side languages like PHP, Ruby, Python, Java, and .Net to build an application, and tools like
MySQL, Oracle, and SQL Server to find, save, or change data and serve it back to the user in front-end
code.
Responsive web design makes your web page look good on all devices.
Editors
Text editors are used to create and modify web pages. HTML ,css , JavaScript etc. codes can be
written in any text editors including the notepad. Some of the popular text editors are given below:
Notepad
Notepad++
Sublime Text Editor etc.
Notepad: Notepad is a basic text editor included with all versions of Microsoft Windows, you can use
this editor for creating simple documents or for creating web pages and any kind of file with given
extension.
To open Notepad, select the Start Windows logo Start button button and then
type Notepad in the search box. Select Notepad from the results.
[Link]
plus/releases/download/v7.9.1/[Link]
[Link]
plus/releases/download/v7.9.1/[Link]
Sublime text editor:
Sublime Text is a code editor software program that allows you to be able to write
code efficiently. Here you can do all that you want within the coding process, and it
has a solid number of plugins and packages to customize the platform directly to your
needs.
Sublime Text 3 is the current version of Sublime Text.
To download sublime text use the [Link] link.
Sublime Text may be downloaded and evaluated for free, however a license must
be purchased for continued use. There is currently no enforced time limit for the
evaluation.
HTML BASIC
HTML stands for HyperText Markup language.
This is the most basic building block of every web application, Without using
HTML we cannot build web applications.
HTML is not a case sensitive.
Example:
<html>
or
<HTML>
or
<HtMl> all these are same effect.
What are required software to create and run the html code.
Step2: Right click on the html file and select open with notepad or any text editor.
Step4: To run html code right click on the html file and open with any web browser.
Now you will see the output in the browser.
</body>
</html>
Heading in HTML:
There are six heading tag available in html. In other word we can say HTML supports 6 heading
tags.
From the above output it is clear that <h1> is the highest and <h6> is the lowest heading.
Total Data will come in a single line, because we are using only one paragraph tag.
Case-2:
<p>This is First Line</p>
<p>This is Second Line</p>
<p>This is Third Line</p>
<p>This is Fourth Line</p>
<img> tag:
In HTML, you can embed an image into a web page using the <img> tag.
When you use this tag, you insert the image URL or address or path. You should
also provide other details such as width, height, and alternative text.
Alternative text is the text that is displayed in the event that your image can't be
displayed. It is useful in the event that someone views your website with images
disabled in their web browser.
Example:
<img src=”[Link]” height=”100” width=”100” alt=”pic of cat” />
<sup> tag: This tag is used to write superscript in a web page.
HTML CODE:
X <sup>2</sup>
HTML Code:
H<sub>2</sub>O
<pre> tag
The HTML <pre> tag is used to specify pre formatted texts. Texts within
<pre>....... </pre> tag is displayed in a fixed-width font. Usually it is displayed in Courier
font. It maintains both space and line break.
Example:
<html>
<head>
<title>demo</title>
</head>
<body >
<pre>
Amhara bihta,
Near iit Main gate
District-patna
</pre>
</body>
</html>
Output
Amhara bihta,
Near iit Main gate
District-patna
<hr> tag : It draw a horizontal line to separate the content in a web page. It is also
called a Horizontal Rule in HTML.
HTML Strikethrough
There are two alternatives you may use instead of the <strike> tags. Both of them look the same
in the output, but convey different semantic meaning:
Example:
<p>My favorite fruit is <del>mango </del> Apple</p>
Output:
My favorite fruit is mango Apple
Example-2:
<p><s>My car is blue.</s></p>
Output: My car is blue.
<a> tag (or anchor tag): This tag is used to creates a hyperlink to web pages, files, email
addresses, locations in the same page etc.
for example
Suppose you wanted to link to the home page of nielit. The web address is:
[Link] You have to code the link like this:
Output:
Homepage of NIELIT
When you click on the above hypertext you will be redirected to home page of NIELIT.
Comment is used to enhance the readability and understandability of the code. HTML comments
are visible to anyone that views the page source code.
<!--this text is ignored/not displayed by the browser-->
Example:
<html>
<head>
<title>demo of html</title>
</head>
<body>
<h1>Hello</h1> <!- -h1 is the highest heading tag in html- ->
</body>
</html>
Output: only hello will be displayed on the web browser.
<html>
<head>
<title>demo of html</title>
</head>
<body>
hello<br>world
</body>
</html>
output:
hello
world
Note: In HTML indentation is not important but tags are important.
====================================
<html>
<head>
<title>demo</title>
</head>
<body background="[Link]">
</body>
</html>
background="image/[Link]"
<html>
<head>
<title>demo of html</title>
</head>
<body>
<marquee direction="right" loop="2" behavior="alternate">welcome to
nielit</marquee>
</body>
</html>
loop attribute in marquee tag is used to specify the how many times to loop.
default is infinite times.
example:
<html>
<head>
<title>demo of html</title>
</head>
<body>
hello  
; world
</body>
</html>
output:
hello world
®
© ©
< <
> >
space
LIST IN HTML:
HTML lists allow web developers to group a set of related items in lists.
1. Ordered List
2. Unordered list
ordered list:
1. Long term course
2. short term course
3. project training
HTML code:
<html>
<head>
<title>demo html</title>
</head>
<body>
<ol type="1">
<li>Long term course</li>
<li>short term course</li>
<li>project training</li>
</ol>
</body>
</html>
example2:
HTML Code:
<html>
<head>
<title>demo html</title>
</head>
<body>
<ol type="1" >
<li>Long term course
<ol type="A">
<li>adhns</li>
<li>o Level</li>
</ol>
</li>
<li>short term course
<ol type="I">
<li>php</li>
<li>java</li>
</ol>
</li>
<li>project training</li>
</ol>
</body>
</html>
Unordered LIST:
HTML CODE:
<html>
<head>
<title>demo html</title>
</head>
<body>
<ul >
<li>Long term course
<ul type="square">
<li>adhns</li>
<li>o Level</li>
</ul>
</li>
<li>short term course
<ul type="disc">
<li>php</li>
<li>java</li>
</ul>
</li>
<li>project training</li>
</ul>
</body>
</html>
Table cells which act as column headers or row headers should use the <th> (table header)
HTML CODE:
<html>
<head>
<title>demo html</title>
</head>
<body>
<table border="1">
<tr>
<td>A</td>
<td>B</td>
</tr>
<tr>
<td>C</td>
<td>D</td>
</tr>
<tr>
<td>E</td>
<td>F</td>
</tr>
</table>
</body>
</html>
HTML CODE:
<html>
<head>
<title>demo</title>
</head>
<body>
<table border="1">
<tr>
<td colspan="2" align="center">A</td>
</tr>
<tr>
<td>B</td>
<td>C</td>
</tr>
</table>
</body>
</html>
Row merge in a table:
B
A
C
<html>
<head>
<title>demo</title>
</head>
<body>
<table border="1">
<tr>
<td rowspan="2">A</td>
<td>B</td>
</tr>
<tr>
<td>C</td>
</tr>
</table>
</body>
</html>
valign="top"
valign="middle"
valign="bottom"
cellpadding attribute:
it is distance between cell wall and content of a table.
cellspacing attribute: it is space between two cell.
Syntax:
<form class="" action="" method="">
.....
</form>
Within the form to collect end user input, we have to use <input> tag.
This <input> tag will play very important role in form creation.
type attribute can be used to specify the type of input end user has to provide. The main important types
are:
text
email
password
color
submit
checkbox
radio
file
etc
name attribute represents the name of input tag. By using this name, in the next target page we can
access end user provided input value.
value attribute represents default value will be displayed in the form.
Eg
<input type="text" name="username" value="Enter User Name"/>
<input type="email" name="mailid" value=""/>
<input type="password" name="pwd" value=""/>
<input type="checkbox" name="course" value=""/>
<input type="radio" name="married" value=""/>
To provide default value it is highly recommended to use placeholder attribute because end user is not
required to delete default value while entering data.
Eg: <input type="text" name="username" placeholder="Enter User Name"/>
HTML FORM Example:
HTML CODE:
<html>
<head>
<title>demo of html form</title>
</head>
<body>
<form method="post" action="[Link]">
<table border="1" cellspacing="0" align="center" height="700"
width="60%"cellpadding="10">
<tr>
<td>choose color:<font color="red">*</font></td>
<td><input type="color" name="colorpick" required/></td>
</tr>
<tr>
<td>Enter Name:<font color="red">*</font></td>
<td><input type="text" name="uname" placeholder="Enter Name" required
maxlength="30" pattern="[a-z A-z]{2,30}"/></td>
</tr>
<tr>
<tr>
<tr>
<td>how many car do you have?</td>
<td><input type="number" name="car" required/></td>
</tr>
<tr>
<tr>
<td>enter email</td>
<td><input type="email" name="email" required/></td>
</tr>
<tr>
<tr>
<td>date of birth</td>
<td><input type="date" name="dob1" required/></td>
</tr>
<tr>
<td>gender:</td>
<td><input type="radio" name="gender" value="M" >Male
<input type="radio" name="gender" value="F"
checked="checked">Female<br></td>
</tr>
<tr><td>hobby : </td>
<td><input type="checkbox" checked="checked"/>cricket<br>
<input type="checkbox" />music<br>
<input type="checkbox" />internet surfing</td>
</tr>
<tr><td>select state:</td>
<td><select name="state">
<option value="-1">--Select--</option>
<option value="35">Andaman and Nicobar Islands</option>
<option value="28">Andhra Pradesh</option>
<option value="12">Arunachal Pradesh</option>
<option value="18">Assam</option>
<option value="10" selected="selected">Bihar</option>
<option value="4">Chandigarh</option>
<option value="22">Chhattisgarh</option>
<option value="26">Dadra and Nagar Haveli</option>
<option value="25">Daman and Diu</option>
<option value="7">Delhi</option>
<option value="30">Goa</option>
<option value="24">Gujarat</option>
<option value="6">Haryana</option>
<option value="2">Himachal Pradesh</option>
<option value="1">Jammu and Kashmir</option>
<option value="20">Jharkhand</option>
<option value="29">Karnataka</option>
<option value="32">Kerala</option>
<option value="37">Ladakh</option>
<option value="31">Lakshadweep</option>
<option value="23">Madhya Pradesh</option>
<option value="27">Maharashtra</option>
<option value="14">Manipur</option>
<option value="17">Meghalaya</option>
<option value="15">Mizoram</option>
<option value="13">Nagaland</option>
<option value="21">Odisha</option>
<option value="34">Puducherry</option>
<option value="3">Punjab</option>
<option value="8">Rajasthan</option>
<option value="11">Sikkim</option>
<option value="33">Tamil Nadu</option>
<option value="36">Telangana</option>
<option value="16">Tripura</option>
<option value="9">Uttar Pradesh</option>
<option value="5">Uttarakhand</option>
<option value="19">West Bengal</option>
</select></td>
</tr>
<tr><td>dob</td>
<td><select name="dd">
<option value="">DD</option>
<option value="01">01</option>
</select>
<select name="mm">
<option value="">MM</option>
<option value="1">january</option>
<option value="2">february</option>
<option value="3">march</option>
</select>
<select name="yyyy">
<option value="">YYYY</option>
<option value="1990">1990</option>
</select>
</td>
</tr>
<tr><td>address</td>
<tr align="center">
<td colspan="2"><input type="submit" name="submit" value="submit form" />
<input type="reset" name="reset" value="clear" /> </td>
</table>
</form>
[Link]
<a href="[Link]" target="_blank"></a>
</body>
</html>
GET POST
Form data sent using this method will Form data sent using this method will
be displayed in the URL. not be displayed in the URL.
This method is not secure, because of This method is secure, because of
security we can not send sensitive security we can send sensitive
information like password with this information like password with this
method. method.
Only text data we can send using this With this method we can send any
method. type of data.
Only limited amount of data we can Any amount of data we can send
send using this method. using this method.
Frame in html:
HTML frames are used to divide your browser window into multiple sections where
each section can load a separate HTML document. A collection of frames in the
browser window is known as a frameset.
To use frames on a page we use <frameset> tag instead of <body> tag. The <frameset>
tag defines, how to divide the window into frames. The rows attribute of <frameset>
tag defines horizontal frames and cols attribute defines vertical frames. Each frame is
indicated by <frame> tag and it defines which HTML document shall open into the
frame.
Code [Link]
<html>
<head>
<title>frame example</title>
</head>
<frameset rows="20%,80%" framespacing="0" frameborder="0">
<frame src="[Link]" name="top" noresize="noresize" />
<frameset cols="20%,80%">
<frame src="[Link]" name="left" noresize="noresize"/>
<frame src="[Link]" name="right" />
</frameset>
<noframes>
<body> your browser does not support frame</body>
</noframes>
</frameset>
</html>
Code of [Link]
<html>
<head>
<title>demo</title>
</head>
<body bgcolor="yellow">
<h1 align="center">NIELIT PATNA CENTRE</h1>
</body>
</html>
Code of [Link]
<html>
<head>
<title>demo</title>
</head>
<body bgcolor="">
<h1> about us page</h1>
</body>
</html>
Code of [Link]
<html>
<head>
<title>demo</title>
</head>
<body bgcolor="red">
<ul>
<li><a href="[Link]" target="right">HOME</a></li>
<li><a href="[Link]" target="right">about us</a></li>
<li><a href="[Link]" target="right">notice</a></li>
</ul>
</body>
</html>
Code of [Link]
<html>
<head>
<title>demo</title>
</head>
<body bgcolor="">
<h1> welcome to nielit patna</h1>
</body>
</html>
Code of [Link]
<html>
<head>
<title>demo</title>
</head>
<body bgcolor="">
<h1> this is latest news page</h1>
</body>
</html>
Output:
===========================END OF HTML============================
Following is the Complete list of HTML Tag for reference only. (All tag is not in your
syllabus) . Following table is taken from [Link]
<base> This tag defines the base URL for all relative URL within the
document.
<basefont> This tag is used to set default font, size and color for all elements of
document. (Not supported in HTML5)
<bdi> This tag is used to provide isolation for that part of text which may
be formatted in different directions from its surrounding text.
<cite> It is used to define the title of the work, book, website, etc.
D
<data> It is used to link the content with the machine-readable translation.
<del> It defines a text which has been deleted from the document.
<details> It defines additional details which user can either view or hide.
<font> It defines the font, size, color, and face for the content. (Not
supported in HTML5)
<ins> It represent text that has been inserted within an HTML document.
<picture> It defines more than one source element and one image element.
Q
<q> It defines short inline quotation.
S
<s> It render text which is no longer correct or relevant.
<small> It is used to make text font one size smaller than document?s base
font size.
<source>> It defines multiple media recourses for different media element such
as <picture>, <video>, and <audio> element.
<tbody> It represents the body content of an HTML table and used along with
<thead> and <tfoot>.
<td> It is used to define cells of an HTML table which contains table data
<template> It is used to contain the client side content which will not display at
time of page load and may render later using JavaScript.
<track> It is used to define text tracks for <audio> and <video> elements.
What is css
Cascading Style Sheets (CSS) is a language designed for describing the appearance
of documents written in a markup language such as HTML.
<style type=”text/css”>
body {
font-size:15px ;
}
</ style >
➤ CSS can be included in its own document and linked to an HTML document by
using the
<link> element.
inline styles:
➤ CSS declarations can be applied directly to an element in an HTML
document by using inline styles with the style attribute.
<style type=”text/css”>
@import url([Link]);
</ style >
CSS Comments:
Comment text gives the web author the ability to add notes to a project so he can
recall why he did something in a certain way or to mark the sections of a document.
Older browsers simply ignores any CSS rules defined inside the HTML comments.
<style type=’text/css’>
<!-- body, td {
color: blue;
}
-->
</style>
Selectors:
In CSS, a selector is the HTML element or elements to which a CSS rule is applied.
Grouping Selectors:
When more than one selector appears in the same rule, they are said to be
grouped. You can group multiple selectors together in a single rule by
providing a comma after each selector.
e.g1:
p, h1, h2, h3, h4, h5
{
font-family: Arial;
color: black;
}
In this example an Arial font and black text is applied to <p>, <h1>, <h2>, <h3>,
<h4> and <h5> elements.
CLASS SELECTORS:
The class name selector begins with a dot, followed by the class name itself, which
you choose.
<style type=”text/css”>
.planet {
margin: 10px 0;
padding: 20px 20px 20px 200px;
border: 1px solid #FFF;
background-position: 20px 20px;
background-repeat: no-repeat;
}
</style>
<div class=”planet”>
<h2>Jupiter</h2>
</div>
ID Selectors:
ID selectors are unique identifiers; an ID is meant to be unique, defined once per
document. To reference an ID, you precede the ID name with a hash mark (or
pound sign, #).
<style type=”text/css”>
#jupiter {
background-image: url([Link]);
}
</style>
<div id=”jupiter”>
<h2>Jupiter</h2>
</div>
*{
font-family: Algerian;
font-size:20px;
}
This rule is applied to all elements contained in the document.
Contextual/DESCENDANT SELECTORS:
In CSS, descendant means an element that is a child, grandchild,
great grandchild, and so on, of another element. Descendant
selectors apply style based on whether one element contains
another. e.g:
.planet h2 {
font-size:
18px;
margin-top:
0;
}
<div class=”planet” id=”jupiter”>
<h2>Jupiter</h2>
<p>Jupiter is the fifth planet from the sun </p>
<a href=”[Link] about nielit patna.</a>
</div>
<div class=”planet”>
<table>
<tr>
<td>
<h2> Some header text </h2>
</td>
</tr>
</table>
</div>
Both hierarchies are valid for the div h2 descendant selector.
In the above example only welcome1 ,welcome 3 are affected. Here welcome 2 is
not the direct child of div tag.
Attribute selectors:
Attribute selectors are used to apply style sheet declarations based
on the presence of attributes or attribute values of an HTML
element.
Attribute Selector: Presence of an Attribute
[attr]
Represents an element with an attribute name of attr.
[attr=value]
Represents an element with an attribute name of attr and whose value is
exactly "value".
<style>
input[name=”ema
il”] { border: 2px
dashed red;
}
</style>
<body>
<input name=”email” type=”text” size=”25” />
</body>
[attr~=value]
Represents an element with an attribute name of attr whose value is a
whitespace-separated list of words, one of which is exactly "value".
EXAMPLE:
<style>
h1[rel~="external"] {
color: red;
}
</style>
<body>
<h1 rel="friend external sandwich">Attribute
Space Separated</h1> </body>
[attr|=value]
Represents an element with an attribute name of attr. Its value can be exactly
“value” or can begin with “value” immediately followed by “-” It can be used
for language subcode matches.
Example:
<style>
h1[rel|="frie
nd"] {
color: red;
}
</style>
<body>
<h1 rel="friend-external-sandwich">Attribute
Dash Separated</h1> </body>
[attr^=value]
Represents an element with an attribute name of attr and whose value is
prefixed by "value". In other hand
The [attribute^="value"] selector is used to select elements whose attribute
value begins with a specified value.
Example:
<style>
h1[align^="cen"]
{
color: red;
}
</style>
<body>
<h1 align=”center”>Attribute Dash Separated</h1>
</body>
Selection Based on Attribute Values That End with a String.
[attr$=value]
Represents an element with an attribute name of attr and whose value is
suffixed by "value". In other hand
The [attribute$="value"] selector is used to select elements whose attribute
value ends with a specified value.
<style>
h1[align^="er"]
{
color: red;
}
</style>
<body>
<h1 align=”center”>Attribute Dash Separated</h1>
</body>
The above example selects all elements with a class attribute value that ends
with "test"
[attr*=value]
Represents an element with an attribute name of attr and whose value contains
at least one occurrence of string "value" as substring.
<style>
h1[class*="gpr"]
{
color: red;
}
</style>
<body>
<h1 class=”testdemo”>welcome to patna center</h1>
</body>
The above example selects all elements with a class attribute value that
contains "gpr".
body {
background-color: red;
background-image: url([Link]);
background-repeat: no-repeat;
background-position: center center;
background-attachment: fixed;
background: #CCC url([Link]) repeat-x fixed top right;
background-size:100% 100%;
background-size: 80px 60px;
}
For example: margin: 70px 100px 50px 100px; (margin: top, right, bottom,left)
Means top margin=70px, right margin=100px and bottom margin=50px and left
margin=100px.
margin: 70px 100px 50px; (margin: top, right and left, bottom).
margin: 70px 100px; (margin: top and bottom, right and left).
margin: 70px; (sets all four sides of an element’s margin to the same value i.e 70
px).
BORDERS:
Borders appear between the margin and padding in the box model. Borders put lines
around boxes.
border-width: 70px 100px 50px; (border-width: top, right and left, bottom).
border-width: 70px 100px; (border-width: top and bottom, right and left).
border-width: 70px; (sets border width of all four sides of an element’s to the same
value i.e 70 px).
border-style: solid dashed solid; (border-style: top, right and left, bottom).
border-style: solid dashed; (border-style: top and bottom, right and left).
border-style: solid; (sets border style of all four sides of an element’s to the same
value i.e solid).
PADDING:
Padding is the space between the content of an element and its borders.
padding: 70px 100px 50px; (padding: top, right and left, bottom).
padding: 70px 100px; (padding: top and bottom, right and left).
padding: 70px; (sets padding for all four sides of an element’s to the same value i.e
70 px).
VISUAL EFFECTS:
FLOATING CONTENT:
float property is used to put content side-by-side in a web pages.
Property Possible value
float
left | right | none
Initial value: none
[Link]
[Link] is a css framework.
how to download [Link] .
Download [Link] from this link: [Link]
[Link] is free to use. No license is necessary.
color in [Link] :
w3-color: this class is used to change the background color.
w3-text-color: this class is used to change the color of a text.
Example:
<html>
<head>
<title>css</title>
<html>
<head>
<title>[Link] example</title>
font in [Link]:
<h1></h1> 36px
<h2></h2> 30px
<h3></h3> 24px
<h4></h4> 20px
<h5></h5> 18px
<h5></h5> 18px
<h6></h6> 16px
<html>
<head>
<title>[Link] example</title>
<link href="[Link]" rel="stylesheet" type="text/css" >
<style>
h1{
font-size:45px;
}
</style>
</head>
<body>
<p class="w3-xxxlarge">welcome to nielit</p>
</body>
</html>
class="w3-tiny"
class="w3-small"
class="w3-medium"
class="w3-large"
class="w3-xlarge"
class="w3-xxlarge"
class="w3-xxxlarge"
class="w3-jumbo"
[Link] CONTAINER:
<html>
<head>
<title>[Link] example</title>
</head>
<body>
<div class="w3-container w3-yellow">
welcome to nielit patna
</div>
</body>
</html>
ex:
<html>
<head>
<title>[Link] example</title>
</head>
<body>
<div class="w3-panel w3-leftbar w3-yellow w3-border-green ">
<p>welcome to nielit patna</p>
</div>
hello
</body>
</html>
w3-panel class add 16px margin to top and bottom, and 16px padding to left
and right in a html element.
w3-leftbar
w3-rightbar
w3-topbar
w3-bottombar
</head>
<body>
<div class="row">
<div class="w3-yellow w3-col s12 m4 l4">
A
</div>
</body>
</html>
Q: write a JavaScript code such that when mouse is over a moving text then it
stop moving and when mouse is out from the moving element then it is start
moving again.
CODE:
<html>
<head>
<title>demo</title>
</head>
<body>
<marquee onmouseover="[Link]();" onmouseout="[Link]()">nielit patna
center</marquee>
</body>
</html>
onmouseover: This javascript event will be executed when mouse is over an
html element.
onmouseout: this javascript event will be executed when mouse is going out of
an html element.
Function in javascript:
A function is a block of code that performs a specific task.
A function is declared using the function keyword.
Syntax:
function function_name()
{
//block of code to be executed.
Example:
<html>
<head>
<title>demo</title>
<script>
function fun1()
{
alert("nielit");
}
</script>
</head>
<body>
<input type="button" value="click here" onclick="fun1()" />
</body>
</html>
The return statement can be used to return the value to a function call.
The return statement denotes that the function has ended. Any code after return is
not executed.
Q:write a javascript code to add two number using javascript and display
the result using alert box.
<html>
<head>
<title>demo</title>
<script>
function fun1()
{
n1=parseInt([Link]("box1").value);
n2=parseInt([Link]("box2").value);
//alert("value of n1="+n1+"value of n2="+n2);
sum=n1+n2;
alert("result="+sum );
</script>
</head>
<body>
enter 1st num<input type="text" id="box1" />
enter 2nd num<input type="text" id="box2" />
<input type="button" value="click here" onclick="fun1()" />
</body>
</html>
Q:write a javascript code to add two number using javascript and display
the result into text box.
<html>
<head>
<title>demo</title>
<script>
function fun1()
{
n1=parseInt([Link]("box1").value);
n2=parseInt([Link]("box2").value);
//alert("value of n1="+n1+"value of n2="+n2);
sum=n1+n2;
[Link]("box3").value=sum;
</script>
</head>
<body>
enter 1st num<input type="text" id="box1" />
enter 2nd num<input type="text" id="box2" />
<input type="button" value="click here" onclick="fun1()" /><br />
result<input type="text" id="box3" />
</body>
</html>
Q:write a javascript code to add two number using javascript and display
the result inside H1 tag.
<html>
<head>
<title>demo</title>
<script>
function fun1()
{
n1=parseInt([Link]("box1").value);
n2=parseInt([Link]("box2").value);
//alert("value of n1="+n1+"value of n2="+n2);
sum=n1+n2;
[Link]("result").innerHTML="result ="+sum;
</script>
</head>
<body>
enter 1st num<input type="text" id="box1" />
enter 2nd num<input type="text" id="box2" />
<input type="button" value="click here" onclick="fun1()" /><br />
<h1 id="result"></h1>
</body>
</html>
<html>
<head>
<title>demo</title>
<script>
function fun1()
{
n1=[Link]("box1").value;
n2=[Link]("box2").value;
n1_final=[Link]();
n2_final=[Link]();
if(n1_final=="")
{
alert("name field cannot be left blank");
return false;
}
else if(n1_final.length<2)
{
alert("name is too small, enter valid name");
return false;
}
else if(n1_final.length>20)
{
alert("name is too big, enter valid name");
return false;
}
else if(n2_final=="")
{
alert("mobile number can not left blank");
return false;
}
else if(n2_final.length!=10)
{
alert("enter 10 digit valid mobile number");
return false;
</script>
</head>
<body>
<form method="post" action="[Link]">
enter name<input type="text" id="box1" /><br>
enter mobile<input type="text" id="box2" maxlength="10"/>
<input type="submit" value="click here" onclick="return fun1()" /> <br />
</form>
<h1 id="result"></h1>
</body>
</html>
syntax:confirm(message);
This method return true if user click on ok button, and return false if user click
on cancel button.
Example:
<html>
<head>
<title>demo</title>
<script>
function fun1()
{
n1=[Link]("box1").value;
n2=[Link]("box2").value;
</script>
</head>
<body>
<form method="post" action="[Link]">
enter name<input type="text" id="box1" /><br>
enter mobile<input type="text" id="box2" maxlength="10"/>
<input type="submit" value="click here" onclick="return fun1()" /> <br />
</form>
</body>
</html>
isNaN(): This function is used to check whether a given value is number or not.
This function return true if value is not a number, and return false if value is a
number.
Example:
<html>
<head>
<title>demo</title>
<script>
function fun1()
{
n1=[Link]("box1").value;
if(isNaN(n1)==true)
{
</script>
</head>
<body>
<form method="post" action="[Link]">
enter number<input type="text" id="box1" maxlength="10"/>
<input type="submit" value="click here" onclick="return fun1()" /> <br />
</form>
</body>
</html>
AngularJS
AngularJS is a JavaScript framework.
AngularJS is open source( it is completely free).
It was developed in 2009 by Misko Hevery and Adam Abrons.
To download AngularJS:
<html>
<head>
<title>demo</title>
<script src="[Link]
</head>
<body>
</body>
</html
OR
<html>
<head>
<title>demo</title>
</head>
<body>
</body>
</html>
Q: write a Code such that when a user type in the text box same is displaying on
the web page simultaneously using JavaScript.
<html>
<head>
<title>angularJS</title>
<script src="[Link]"></script>
<script>
function view()
var a=[Link]("box1").value;
[Link]("d").innerHTML=a;
</script>
</head>
<body>
</body>
</html>
Q: write a Code such that when a user type in the text box same is displaying on
the web page simultaneously using AngularJS.
<html>
<head>
<title>angularJS</title>
<script src="[Link]
</head>
<body>
<div ng-app="">
<h1>{{name}} </h1>
</div>
</body>
</html>
Explanation:
<div ng-app=””>…</div> indicates that AngularJS script is used inside this tags.
<script src="[Link]
Expression in AngularJS
Syntax:
{{expression}}
Example:
<html>
<head>
<title>angularJS</title>
<script src="[Link]"></script>
</head>
<body >
<div ng-app="">
<h1> {{2+3+4}}</h1>
</div>
</body>
</html>
Output:
Example2:
<html>
<head>
<title>angularJS</title>
<script src="[Link]"></script>
</head>
<body >
<div ng-app="">
<h1> {{“hello”+”world”}}</h1>
</div>
</body>
</html>
Output:
Example3: write a code to add two number using AngularJS, input is taken from the html form.
<html>
<head>
<title>angularJS</title>
<script src="[Link]"></script>
</head>
<body ng-app="">
<div ng-init="">
<h1> {{(n1-0)+(n2-0)}}</h1>
</div>
</body>
</html>
Alternate Method:
<html>
<head>
<title>angularJS</title>
<script src="[Link]"></script>
</head>
<body ng-app="">
<div >
<h1 ></h1>
</div>
</body>
</html>
ng-bind directive:
this directive is used to replace the content of an html element with the value of given variable or
expression.
Example:
<html>
<head>
<title>angularJS</title>
<script src="[Link]"></script>
</head>
<body ng-app="">
<div >
<h1 ng-bind="n1+n2"></h1>
</div>
</body>
</html>
Output:
After addition of the text box content result will be displayed inside H1 tag.
===============END OF AngularJS=================