Chapter 4
Chapter 4
Java Script
AU/Computer Sc. Dept/Internet Programming( CoSc 3081)
lecture slides
Introduction
JavaScript is the world's most popular programming
language.
JavaScript is the programming language of the Web.
JavaScript is easy to learn.
A scripting language is a lightweight programming
language.
JavaScript code can be inserted into any HTML page, and
it can be executed by all types of web browsers.
AU/Computer Sc. Dept/Internet Programming( CoSc 3081)
2 lecture slides
…
Why JavaScript?
JavaScript is one of the 3 languages all web developers must learn:
1. HTML to define the content of web pages
Java script is case sensitive (lower-case and upper-case letters have different
meaning)
Java script code can be used either in head or body part.
Use semicolon at the end of single line code.
Using innerHTML
To access an HTML element, JavaScript can use the
document.getElementById(id) method.
• On the code above, a button called "click" will display on the browser.
• Then when you click on the button, "Heading text" will display above the
button with <h1> property.
• This happens because, when the user clicks on the button, the function
"try1" is called and code under try1 will execute.
Variable names can contain letters, digits, underscores, and dollar signs.
17
…
You can declare many variables in one statement.
Just start the statement with var and separate the variables by
comma:
Example
Example:
Example:
<script>
document.write(4 + 5 + "love"); //9love
document.write("love" + 4 + 5); //love45
</script>
if (condition)
{
code to be executed if
condition is true
}
if (condition)
{
//code to be executed if condition is true
}
else
{
//code to be executed if condition is not true
}
{ var i=0;
} {
document.write(i);
i++;
}
</script>
If the condition is true, and then it will repeat the loop as long as the
condition is true.
do
{
code block to be executed
}
while (condition);
Continue Statement
The continue statement breaks one iteration (in the loop), if a
specified condition occurs, and continues with the next iteration
in the loop.
OUTPUT
OUTPUT
When the function called, it goes to java script code and execute the block
code under the function "try1()".
"info" is the name of the form and "name" is the name of the first input box
"value" represents the content that the user enters on that text box.
"if(x=="“)" checks if the user doesn't enter any value, then message box will
display.
AU/Computer Sc. Dept/Internet Programming( CoSc 3081)
43 lecture slides
Lab 2: Java script and HTML
Thank You..!!!