This document provides an introduction to JavaScript and jQuery, highlighting JavaScript's role as a client-side scripting language that enhances HTML interactivity. It covers key concepts such as the Document Object Model (DOM), dynamic HTML (DHTML), and various programming elements including variables, operators, and control statements. Additionally, it discusses development environments for JavaScript, methods for integrating scripts into HTML, and the use of popup boxes for user interaction.
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
0 ratings0% found this document useful (0 votes)
19 views65 pages
WebTechUnit1 Part1
This document provides an introduction to JavaScript and jQuery, highlighting JavaScript's role as a client-side scripting language that enhances HTML interactivity. It covers key concepts such as the Document Object Model (DOM), dynamic HTML (DHTML), and various programming elements including variables, operators, and control statements. Additionally, it discusses development environments for JavaScript, methods for integrating scripts into HTML, and the use of popup boxes for user interaction.
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
You are on page 1/ 65
UNIT-4
Introduction«to JavaScript & jQueryIntroduction to JavaScript
Understanding JavaScript:
- JavaScript is the most Popular scripting language(Client side)
- JavaScript was designed to add interactivity to HTML pages
- you can make your webpage more lively and interactive with the help
of JavaScript.
- Ascripting language is a lightweight programming language
- JavaScript is usually embedded directlyinto HTML pages
- JavaScript is interpreted language
- Free of cost Scripting Language
- JavaScript is also being used: Widely in game development and Mobile
application development.
The
2. Integrating script with tag
Document title
3. Importing External JavaScript
Document title
Javascript demo program:
Basic of JavaScript programming & Elements
A computer program is a list of "instructions" to be "executed" by a
computer.
In a programming language, these programming/instructions are
called statements.
A JavaScript program is a list of programming.statements ended with ;.
JavaScript statements can be grouped together in code blocks, inside
curly brackets {
Elements of JavaScript:
JavaScript comments:
JavaScript comments canbe used to explain JavaScript code, and to
make it more readable.
Comments are nomexecutable code of the program.
Single line comments start with //.
Multi-line’comments start with /* and end with */.
Any text between /* and */ will be ignored by JavaScript.JavaScript Statements
* JavaScript statements are composed of:
* Values, Operators, Expressions, Keywords, and Comments,
JavaScript Values
* The JavaScript syntax defines two types of,values:
* Fixed values: Fixed values are called\Literals.
* Variable values: Variable values are called Variables.
JavaScript Literals
* The two mostimportant syntax rules for fixed values are:
1. Numbers ar@written with or without decimals:
Ex:,100, 10.5
2. Strings are text, written within double or single quotes: "John Doe“
‘John Doe‘JavaScript Variables:
In a programming language, variables are used to store information.
JavaScript uses the var keyword to declare variables.
An equal sign is used to assign values to variables.
While naming your variables in JavaScript, keep:the following rules in mind.
- You should not use any of the JavaScript.reserved keywords as a variable
name.
- You can not use mathematical orlogical operator in a variable name.
- JavaScript variable names should not start with a numeral (0-9). They must
begin with a letter or an.underscore character.
- JavaScript names must not'’contain spaces ever.
- JavaScript variable,names are case-sensitive.
Variable declaration:
var-pi =3.14;
vanperson = "John Doe";
var Z=x+y;// Example of variable
w
. OnMouseMove:
Execute a JavaScript when moving the mouse pointer over a-specific
html element:
User can define this event in any html tag.
Syntax:
OnMouseover:
Execute a JavaScript when movingthe mouse pointer over a specific
html element:
User can define this event'in any html tag.
Syntax:
5. OnMouseout:
* The onmouseout event occurs when the mouse pointer is moved out of
an element.
* User can define this event in any html tag.
* Syntax:
6. OnMouseup & Onmousedown;
* The onmouseup event occurs when a user releases a mouse button
over an element.
* The onmousedowmeyent occurs when a user presses a mouse button
over an element.
* Syntax:
Keyboard Events
In JavaScript keyboard events are performing while keyboard Key is
pressed or released.
This event work with form tag elements like textbox, textarea, email,
number etc.
There are three main keyboard events .
OnKeypress
onKeyup
onKeydown
. onKeypress :
The onkeypress event occurs when the user presses a key (on the
keyboard).
The onkeypress-event is not fired for all keys (e.g. ALT, CTRL, SHIFT,
ESC) in all browsers.
To detect-only whether the user has pressed a key, use
the onkeydown event instead, because it works for all keys.
Syntax?
EX: . onKeyup:
The onkeyup event occurs when the user releases a key (on the
keyboard).
It is little bit faster than keydown and keypress.
Syntax:
Ex:
. onKeydown:
The onkeydown event occurs when the user is pressing a key (on the
keyboard).
It will start reacting’after second time keydown.
It is little bit’slower than keyup() event and similar to the keypress
event.
Syntax:
Ex: Example of onkeyup and onkeydown:
Key up and down change background of the text field
RPWNR
Form Events
A form event is fired when a form control receive or loses\focus\or when
the user modify a form control value such as by typing,text in a text
input, select any option in a select box etc.
Here are some most important form events and,their event handler.
onfocus
onblur
onchange
onsubmit1. onfocus:
* The focus event occurs when the user gives focus to an element on a
web page.
You can handle the focus event with the onfocus event handler.
* Syntax:
Ex:
2. onblur:
This event occurs when the.user takes the focus away from a form
element. The onblur-evehthandler is used to handle this event.
° Syntax:
Ex: 3. onchange:
The change event occurs when a user changes the value-of a form
element.
You can handle the change event with the onchange() event handler.
This event trigger when you change the option in the form select box.
4. onsubmit:
The submit event occurs when \the submit button is clicked.
The onsubmit() event handler is used to handle this event.
* Syntax :
Ex: