UNIT 5 DHTML,CSS& JAVASCRIPT
UNIT 5 DHTML,CSS& JAVASCRIPT
Introduction of DHTML:
1. HTML
2. JavaScript - the Web's standard scripting language
3. Cascading Style Sheets (CSS) – Making web page more attractive.
4. Document Object Model (DOM) -- a means of accessing a document's individual elements
- The application of DHTML was introduced by Microsoft with the release of Internet Explorer
4 in 1997.
We put HTML tags (paragraphs, images, etc.) in a specific order in the source code. The
browser always showed all elements in this order. Positioning and styling was done by
tables, div's and such aids. If we wanted to change the order or the positioning of the
elements, we had to rewrite the HTML.
DHTML gives us the chance to re-organize our pages. In fact, we can take some tags out of
the natural flow (Default behavior) of the page. The natural flow of the page is the page as
the browser first shows it. It calculates the tables and paragraphs and other things we put
in the page, then displays them in the best possible way, one by one, from the beginning
to the end of the HTML document.
It provides a richer, more dynamic experience on web pages, making them more like
dynamic applications and less like static content.
Ramification/Components of DHTML:
DHTML depends on these four component and these are:
1) HTML: we have been using attributes, tags, and generating HTML in a structured fashion.
HTML defines the structure of a Web page, using such tags as headings, forms, tables,
paragraphs and links.
each of the button’s states—inactive, active, and unavailable.
To run this concept we need three images, a sample set of rollover image is shown here:
Step 1: Create three images as shown below and give name as shows.
Image First
Image1.jpg
Click
Here
Image Second
Image2.jpg
Image Third
Image3.jpg
Step 2: Take <a>tag and place <img> tag inside <a> tag then apply onmouseover and
onmouseout event in <a> tag.
Step 3: In order to add this rollover image to the page, simply use the <IMG> tag like
another image it will display image1.jpg.
The idea is to swap the image in and out when the user move mouse cursor over the image
the onmouseover event will occur and image2.jpg will appear and when mouse pointer
switch back from the image onmouseout event will occur and image3.jpg will appear. By
literally swapping the value of the SRC attribute, you can achieve the rollover effect. This
will happen dynamically without manually change any code and refresh or reload a web
page.
Output Effect: This will show effect as like image of ABOUT will blink as per action from
white background to black background but technically image is not blinked but two individual
images are swapping on action.
Program for Rollover Buttons:
<html>
<head><title> Rollover Buttons without using javascript </title></head> <body>
<a href='Destination URL' target="_top" onmouseover="document.
Rollover.src='path/image2.jpg'" onmouseout="document.
Rollover.src='path/image3.jpg'">
CSS handles the look and feel/designing part of a web page. Using CSS, you
can control the color of the text, the style of fonts, the spacing between
paragraphs, how columns are sized and laid out, what background images or
colors are used, layout designs, and variations in display for different devices
and screen sizes as well as a variety of other effects.
CSS is easy to learn and understand but it provides powerful control over the
presentation of an HTML document. Most commonly, CSS is combined with
the markup languages HTML.
Advantages of CSS
You can write CSS once and then reuse same sheet in multiple HTML
pages. You can define a style for each HTML tags and apply it to as
many Web pages as you want.
Just write one CSS rule of a tag and apply it to all the occurrences of
that tag. So less code means faster webpage download times.
3) Easy maintenance –
To make a global change, simply change the style, and all tags in all
the web pages will be updated automatically.
CSS has a lot of attributes than HTML, so you can give a best look to
your HTML page in comparison to HTML attributes.
5) Multiple Device Compatibility –
Style sheets allow content to be displayed for Mobiles, Tablets,
laptops, Desktop Computers, etc.
7) Platform Independence –
Types of CSS:
There are three types of CSS:
- This type of css applies for complete webpage and for all tags, suppose
you write a css code for h1, h2, p tag then all h1, h2 and p tags are
available inside that web page are applied by css effect.
- Embedded css is easy way to apply designing for all tags with short and
one time written code. That means you have to write only once as css
code in style tag and it applies for all tags so it’s a short cut method to
write designing code.
- Inline style applies css code inside the tag, we can say it is a tag specific
css. It is a single tag oriented css code, which does not disturb the other
same tags. it is possible to set the style for an individual tag.
- For using this css you have to write style attribute inside a start tag of any
valid HTML tag, then apply css code as shown below in example.
- Consider you have a webpage which contain more than one <H1> tag,
and the css design code apply only one <H1> tag among them all tags,
so css design effect apply only for that H1 tag which has above example
css code, remaining H1 does not give css output effect.
EXAMPLE:
Step1: h1
{ font-size: 40pt;
Open notepad application and write css code there,
fontfamily: Arial; color:
then use Save As option and give filename style.css. In
green;
this way you created a css code file. Following code is
present in that style.css file. }
Introduction of JavaScript:
Advantages of JavaScript:
Disadvantages of JavaScript:
Client-side JavaScript:
The script should be included in or referenced by an HTML
document for the code to be interpreted by the browser.
It means that a web page need not be a static HTML, but can
include programs that interact with the user, control the
browser, and dynamically create HTML content.
Dreamweaver MX
Macromedia
HomeSite 5
This function can be used to write text, HTML, or both. Take a look
at the following code.
<html>
<head>
<title>Javascript Example</title>
</head>
<body>
</script>
</body>
</html>
This code will produce the following result –
Hello World
JavaScript Variables:
<script type="text/javascript">
var money=100; var
name=”Suraj”;
</script>
Example program to display calculated value for variable z:
<html>
<title>Addition Using JavaScript</title>
<body>
<p>Output of variable z is as follows</p>
<script type="text/javascript"
language="javascript"> var x =
5; var y = 6; var z = x + y;
document.write(z);
</script>
</body>
</html>
Note –
1. Use the var keyword only for declaration or initialization, once
for the life of any variable name in a document. You should not
re-declare same variable twice with same name such as var
x=10; and var x=20; in same program.
JavaScript Variable Names Rules:
While naming your variables in JavaScript, keep the following three
rules in mind.
1) JavaScript variable names should not start with a numeral
(0-9).
Input and Output statements:
2) Document.getElementById("demo").innerHTML = "any
string message";
Example:
<html>
<head>
<title>Take Input from User and Give Output to
User</title>
</head>
<body>
<input type="text" id="userInput">give me
input</input>
<button onclick="test()">Submit</button>
<script type="text/javascript" language="javascript">
function test()
{
var uservalue= document.getElementById("userInput").value;
document.write(uservalue);
}
</script>
</body>
</html>
Validating form:-
JavaScript provides a way to validate form's data on the client's
computer before sending it to the web server. Form validation
generally performs two functions.
----------------------------------------------THE END-----------------------------------------------