Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 13

Introduction to JavaScript

Introduction

JavaScript is a scripting language.


JavaScript is a programming language commonly used in web
development. It add dynamic and interactive elements to websites.
JavaScript is a client-side scripting language, which means the source
code is processed by the client's web browser rather than on the web
server.
JavaScript functions can run after a webpage has loaded without
communicating with the server. For example, a JavaScript function
may check a web form before it is submitted to make sure all the
required fields have been filled out. The JavaScript code can produce
an error message before any information is actually transmitted to the
server.
Extension of java script is .js

Characteristics :
Enhances functionality and appearance
Client-side scripting
Makes pages more dynamic and interactive
Program development
Program control

Why we use JavaScript?


Browsers
Text,

have limited functionality

images, tables, frames

JavaScript

allows for interactivity


Browser/page manipulation
Reacting

A type

to user actions

of programming language

Easy

to learn

JavaScript Allows Interactivity


Improve

appearance

Especially

graphics
Visual feedback
Perform

calculations
Validation of input

How Does It Work?


Embedded
View

within HTML page

source

Executes

on client

Fast

Simple

programming statements combined with


HTML tags
Interpreted (not compiled)

No special tools required

What is the difference between Java and java script?

Totally

different
A full programming language
Much harder!
A compiled language
Independent of the web

JavaScript Statements
<html>
<head><title>My Page</title></head>
<body>
<script language="JavaScript">
document.write('This is my first
JavaScript Page');
</script>
</body>
</html>

Note the symbol for


line continuation

JavaScript Statements
<html>
<head><title>My Page</title></head>
<body>
<script language=JavaScript">
document.write('<h1>This is my first
JavaScript Page</h1>');
</script>
</body>
</html>

HTML written
inside JavaScript

JavaScript Statements
<html>
<head><title>My Page</title></head>
<body>
<p>
<a href="myfile.html">My Page</a>
<br />
<a href="myfile.html"
onMouseover="window.alert('Hello');">
My Page</A>
</p>
JavaScript written
An Event
</body>
inside HTML
</html>

Form Elements in HTML

<form name="addressform">
Name: <input name="yourname"><br />
Phone: <input name="phone"><br />
Email: <input name="email"><br />
</form>

Forms and JavaScript


document.formname.elementname.value
Thus:
document.addressform.yourname.value
document.addressform.phone.value
document.addressform.email.value

Using Form Data


Personalising an alert box

<form name="alertform">
Enter your name:
<input type="text" name="yourname">
<input type="button" value= "Go"
onClick="window.alert('Hello ' +
document.alertform.yourname.value);">
</form>

You might also like