0 ratings0% found this document useful (0 votes) 23 views130 pagesJS
it is a document for learning the javascript easily
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
JavaScript
JavaScript for Beginners
Course notes
<_/>
_
DOWNLOAD PDF « EICODING BUGS ENOTES GALLERYJavaScript for Beginners 2
1 Whatis a Programming Language? 5
Koy Points 5
2 Server-side vs. Client-side 7
Key Points 7
3 About JavaScript .
Key Points
4 A Tour of Javaserip..
Key Points
Project.
5 Objects, Properties and Methods 18
Key Points| 18
Assigning Values to Properties 24
Key PINS sn
Project.
7 About Comments.
Key Points
Project.
8 Hiding Scripts from Older Browsers. 28
Key Points 28
Project. 29
9 Automatically Redirecting the User...
Key Points
Project.
3
10 Alert, Prompt and Confirm 33
Key Points 33
Project... =
11. Variables and Operators.
Key Points
Project.
12 Comparisons. 40
Koy Points wo
Project. “1
13. Conditionals ..
Key Points
Project
Project 2
DOWNLOAD POF « EICODING BUGS [NOTES GALLERYJavaScript for Beginners 3
14 Looping
Key Points
Projet.
TS AMAYS ses 7 . seven 7
Key points 53
Project. 55
16 Associative & Objective Arrays 87
Key Points 57
Project... ~
17, Two Dimensional Arrays...
Key Points
Project.
18 String Manipul 6
Key Points et
Project. 65
19 Using Functions...
Key Points
Project.
20 Logical Operators 7
Key Points n
Project. - 74
21. Using Event Handlers ...
Key Points
Project.
22 Working with Images 79
Key Points 79
Project... : 80
23. Simple Image Rollovers...
Key Points
Project.
24 Object Instantiation and Better Rollovers 85
Key Points 85
Project. 86
25° Working with Browser Windows...
Key Points
Project
26 Positioning Browser Windows 91
Key Points| 9
Project. 92
DOWNLOAD PDF = EICODING BUGS ENOTES GALLERYJavaScript for Beginners 4
27 Focus and Blur.
Key Points,
Project...
28 Dynamically Created Content...
Key Points
Project.
29 Working with Multiple Windows. 97
Key Points 97
Project... : = 98
30. Using an External Script File.....
Key Points
Project
31 Javascript and Forms. 101
Key Points 101
Project 103
32 Form Methods and Event Handlers ... . enensene 105
Key Points| 405,
Project 106
33 JavaScript and Maths. 108
Key Points, 108
Project... 109
34 Object Variables — A Refresher . seven
Key Points 111
Project. 2
35. Actions From Menu Items 113
Key Points 113
Project... “ mot
36 Requiring Form Values or Selections..... . seven
Key Points 116
Project 8
37 Working with Dates 121
Key Points 121
Project 122
38. Retrieving Information from Date Objects.. 123
Key Points| vs ve onion 123
Project 124
39. Creating a JavaScript Clock 126
Key Points| 126
Project. 128JavaScript for Beginners 5
1 What is a Programming Language?
Key Points
°
A programming language is a set of codes that we can use to
give a computer instructions to follow.
Popular and well-known programming languages include Java,
C++, COBOL, BASIC, LISP and more. Most popular
programming languages consist of words and phrases that are
similar in form to the English language.
‘A well-written program will be easily readable by anyone with
alittle programming experience, regardless of whether they
have any direct experience of the language in question. This is
because modern programming languages share a large number
of common concepts. In particular, they all have a notion of
variables, arrays, loops, conditionals, and functions. We will
meet these concepts again in more depth later in the course.
Traditionally, programming languages have been used to write
(for the most part) “stand-alone” applications. Things like
Microsoft Word, Mozilla Firefox and Lotus Notes are all
examples of such applications. Once installed on a PC, these
applications run without necessarily requiring any other
software to be installed alongside them.
Web Applications differ from these traditional applications in
many respects, but the most striking is that they all run inside
your web browser. Examples of popular web applications are
things like Google, Hotmail, Flickr, GMail and any of the vast
array of “weblogging” systems.
DOWNLOAD PDF « EICODING BUGS ENOTES GALLERYJavaScript for Beginners
© These applications are also written using programming
languages, but as a rule they are built using multiple,
interdependent technologies. These technologies are easily
(though not completely) broken down into two categories:
server-side and client-side.JavaScript for Beginners 7
2 Server-side vs. Client-side
Key Points
°
The World Wide Web is built on a number of different
technologies.
For most users, the web starts and ends with their choice of
web browser. The browser is said to define the client-side of
the web, with the browser, the computer it is running on, and
the user surfing the web being collectively referred to as the
client.
Consider a client who has decided to visit the web site at
www.google.com. The first thing that happens is that the client
will make a request to Google’s web server for the default
page of that web site.
The web server is an application running on a computer
owned by Google. Like the client, the server application and
the computer on which it runs define the server-side of the
web, and are collectively referred to as the server.
When the server receives the request from the client for a
particular page, its job is to retrieve the page from the
computer's files and serve it back to the client. In many cases,
this operation is a very simple procedure involving little or no
work on the part of the server.
However, using a programming language like PHP, Perl or
Java, we can cause the server to either modify the page it finds
before it passes it back to the client, or even to generate the
page entirely from scratch. This is referred to as a server-side
application. The page passed back to the client looks (to the
client) exactly the same as any other page that has not been
modified.
DOWNLOAD POF é EICODING BUGS CINOTES GALLERYJavaScript for Beginners
© An example of a server-side application might be to insert the
current date and time into a page. This would mean that each
time the page was requested (say, by using the browser's
refresh button), a new time value would be added to the page.
© Once the client has received the page from the server, it
displays the page and waits for the user to request another
page. As soon as the page reaches this state, it has moved
beyond the control of the server. No server-side application
can now alter the contents of the page without the client having
to make another trip back to the server to get a new (and
possibly updated) copy of the page.
© However, all modern browsers allow for the running of elient-
side applications. These are small applications which are
embedded within the HTML code of the page itself.
© Server-side applications ignore any client-side applications
that they find while modifying pages to send to the client, so in
general the two types of application cannot easily “talk” to
each other.
© However, once the client has received a client-side
application, it can begin to modify the page dynamically,
without the need to go back to the server.
© An example of a client-side application might be a clock on a
web page that updated every second.
© Anunfortunate side effect of client-side applications is that all
the code must be sent to the client for running, which means
that the application’s inner workings are available for anyone
to see. This makes it impractical for checking passwords, or
doing anything else that could cause confidential information
to be released into the wild.
© In addition, all modern web browsers afford the user the
opportunity to switch off client-side applications altogether.
On top of this, the way the same client-side application is run
will vary from browser type to browser type.
© Despite these drawbacks, client-side applications (or seripts,
as they are better known due to their general brevity) remain
the best way to provide web users with a rich environment
when developing web applications.JavaScript for Beginners
°
In short, the two technologies each have their strengths and
weaknesses:
Client-side scripts allow the developer to alter pages
dynamically, and to respond to user actions immediately rather
than having to wait for the server to create a new version of the
page. However, there are security and cross-browser
compatibility issues to be aware of, and these are often non-
trivial.
Server-side applications allow the developer to keep her code
secure and secret, thus allowing for more powerful
applications to be created. In addition, since the server running
the code is always a known quantity, applications that run
suecessfllly in one browser will run successfully in all
browsers. However, despite all this power, there is no direct
way for a server-side application to alter a page without
having to force the client-side to load another page. This
makes it completely impractical for things like drop-down
menus, pre-submission form checking, timers, warning alerts
and so forth.JavaScript for Beginners 10
3 About JavaScript
Key Points
© JavaScript is an interpreted, client-side, event-based, object-
oriented scripting language that you can use to add dynamic
interactivity to your web pages.
© JavaScript scripts are written in plain text, like HTML, XML,
Java, PHP and just about any other modern computer code. In
this code, we will use Windows NotePad to create and edit
our JavaScript code, but there are a large number of
alternatives available. NotePad is chosen to demonstrate
JavaScript’s immediacy and simplicity.
© You can use JavaScript to achieve any of the following:
= Create special effects with images that give the
impression that a button is either highlighted or
depressed whenever the mouse pointer is hovered over it.
= Validate information that users enter into your web
forms.
* Open pages in new windows, and customise the
appearance of those new windows.
= Detect the capabilities of the user’s browser and alter
your page’s content appropriately.
* Create custom pages “on the fly” without the need for a
server-side language like PHP.
= And much more...JavaScript for Beginners
°
JavaScript is not Java, though if you come from a Java
background, you will notice that both languages look similar
when written, Java is a full featured and comprehensive
programming language similar to C or C++, and although
JavaScript can interact with Java web applications, the two
should not be confused.
Different web browsers will run your JavaScript in different,
sometimes incompatible ways. In order to work around this, it
is often necessary to use JavaScript itself to detect the
capabilities of the browser in which it finds itself, and alter its
operation depending on the result.
To revisit the original definition in this chapter, note the
following points:
= Interpreted refers to the fact that JavaScript code is
executed (acted on) as it is loaded into the browser. This
is a change of pace from compiled languages like Java,
which check your program thoroughly before running a
single line of code, and can have many implications that
can catch you out if you are from a non- interpreted
programming background.
= Client-side has been defined already in the previous
chapter.
= Event-based refers to JavaScripts ability to run certain
bits of code only when a specified event occurs. An
event could be the page being loaded, a form being
submitted, a link being clicked, or an image being
pointed at by a mouse pointer.
* Object-oriented signals that JavaSeript’s power to
exert control over an HTML page is based on
manipulating objects within that page. If you are familiar
with object-oriented programming, you will be aware
of some of the power that this can bring to the coding
environment.
"JavaScript for Beginners 12
© One final note: While JavaScript is a programming language,
HTML (the language of the World Wide Web) is not. HTML.
is a Markup Language, which means that it can be used to
mark areas of a document as having special characteristics like
headers, paragraphs, images, forms and so on, but it cannot
perform any logical processing on its own. So while
JavaScript is often written alongside HTML, the rules of one
do not necessarily have any bearing on the other.JavaScript for Beginners 13
4 A Tour of JavaScript
Key Points
°
Project
°
Let’s start with a quick tour of the major features of
JavaScript. This chapter is intended to be a showcase of what
JavaScript can do, not an in depth investigation into the
deeper concepts, so don’t worry too much if you get lost or
don’t understand the code you're typing in!
Our JavaScript is all going to be written using NotePad.
Open NotePad and save the resulting empty document in your
user drive as chapter_4. html.
Begin by creating a basic HTML page in your blank document.
It doesn’t have to be anything fancy — the following will be
more than sufficient:
Codestin Search App
A Tour of JavaScript