Basic Program Using Javascripit For Practice
Basic Program Using Javascripit For Practice
What is DHTML?
The DHTML stands for “dynamic hypertext transfer markup language”. DHTML is not
a language. It is basically a collection of web technologies that are used together to create
robust interactive web applications. The web page’s behavior will change in response to the
user’s behaviors.
DHTML i
s a combination of three technologies such as HTML, CSS, and JavaScript.
HTML defines web sites content through semantic tags (heading, sections, articles,
paragraphs, lists)
CSS described the look and formatting of a document
Layout and position of elements on the page
Presentation styles (background, border, colors…)
Text and font styles (size, color, family)
JavaScript defines dynamic behavior
Programming logic for interaction with the user
Handle user events
HTML, CSS, and JavaScript are the three layers of the Web that helps to make
web pages interactive.
What can JavaScript do?
Can handle events such as button clicks
Can read/ write HTML elements and modify the DOM tree dynamically
It Can access/modify the browser cookies.
It can detect the user browser as well as the Operating System (OS) of the user.
We can also Implement the object-oriented language features using JavaScript
It is also used to make asynchronous server calls (i.e. AJAX calls)
Can implement complex graphics and animation via Canvas
It is also possible to implement back-end logic using Node.js
<html>
<body>
<h1>Demo: JavaScript Variables </h1>
<p id="p1"></p>
<p id="p2"></p>
<p id="p3"></p>
<p id="p4"></p>
<p id="p5"></p>
<script>
var myvariable = 1; // numeric value
document.getElementById("p1").textContent = myvariable;
<p id="p1"></p>
<p id="p2"></p>
<script>
var str1 = "Hello World";
document.getElementById("p1").textContent = str1;
document.getElementById("p2").textContent = str2;
</script>
</body>
</html>
<!DOCTYPE html>
<html
<head>
<meta charset="utf-8">
<title>JavaScript how to Add Parameters to a Function</title>
</head>
<body>
<script>
// Defining function
function Sum(num1, num2)
{
var total = num1 + num2;
document.write(total);
}
// Calling function
Sum(6, 20); // Prints: 26
document.write("<br>");
Sum(-5, 17); // Prints: 12
</script>
</body>
</html>
<!DOCTYPE html>
<html
<head>
<meta charset="utf-8">
<title>JavaScript how to Add Parameters to a Function</title>
</head>
<body>
<script>
// Defining function
function Sum(num1, num2)
{
var total = num1 + num2;
document.write(total);
}
// Calling function
Sum(6, 20); // Prints: 26
document.write("<br>");
Sum(-5, 17); // Prints: 12
</script>
</body>
</html>
[5].
<!DOCTYPE html>
<html >
<head>
<meta charset="utf-8">
<title> JavaScript</title>
</head>
<body>
<p id="great"></p>
<p id="result"></p>
<script>
// Writing text string inside an element
document.getElementById("great").textContent/innerHtML = "Hello World!";
ALERT
CONFIRM
PROMPT
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Alert</h2>
<button onclick="firstFunction()">Try it</button>
<script>
function firstFunction()
{
alert("Hello\nHow are you?");
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<script>
function firstFunction()
{
var r = confirm("Confirm something!");
if (r == true) {
x = "OK was pressed";
}
else {
x = "Cancel was pressed";
}
document.getElementById("test").innerHTML = x;
}
</script>
</head>
<body>
<h2>JavaScript Confirm Box</h2>
<p id="test"></p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<script>
function firstFunction()
{
var txt;
var person = prompt("Please enter your full name:", "GEHU");
<body>
<h2>JavaScript Prompt</h2>
<p id="test"></p>
</body>
</html>