JavaScript Training in Ambala ! Batra Computer Centre

30
JAVASCRI PT TRAINING IN AMBALA

Transcript of JavaScript Training in Ambala ! Batra Computer Centre

Page 1: JavaScript Training in Ambala ! Batra Computer Centre

JAVASCRIPT TRAINING

IN AMBALA

Page 2: JavaScript Training in Ambala ! Batra Computer Centre

Today We’ll Learn Javascript What is javascript Are Java & Javascript the Same? How to put javascript in an HTML page Ending statement with a Semicolon? Javascript Variables Operators in Javascript Popup Boxes in javascript

Ph. No. :9729666670,4000670 Website: www.batracomputercentre.com

Page 3: JavaScript Training in Ambala ! Batra Computer Centre

JAVASCRIPTJavaScript is used in millions of Web pages to

improve the design, validate forms, detect browsers, create cookies, and much more.

JavaScript is the most popular scripting language on the internet, and works in all major browsers, such as Internet Explorer, Mozilla, Firefox, Netscape, Opera.

Ph. No. :9729666670,4000670 Website: www.batracomputercentre.com

Page 4: JavaScript Training in Ambala ! Batra Computer Centre

WHAT IS JAVASCRIPT JavaScript was designed to add interactivity to HTML

pages JavaScript is a scripting language (a scripting language is

a lightweight programming language) A JavaScript consists of lines of executable computer

code A JavaScript is usually embedded directly into HTML

pages JavaScript is an interpreted language (means that scripts

execute without preliminary compilation) Everyone can use JavaScript without purchasing a license

Ph. No. :9729666670,4000670 Website: www.batracomputercentre.com

Page 5: JavaScript Training in Ambala ! Batra Computer Centre

Are Java And Javascript The Same?

NO! Java and JavaScript are two completely

different languages in both concept and design!

Java (developed by Sun Microsystems) is a powerful and much more complex programming language - in the same category as C and C++.

Ph. No. :9729666670,4000670 Website: www.batracomputercentre.com

Page 6: JavaScript Training in Ambala ! Batra Computer Centre

How to put a javascrpit into an HTML page

<html><body><script type="text/javascript">document.write("Hello World!")</script></body></html>

Ph. No. :9729666670,4000670 Website: www.batracomputercentre.com

Page 7: JavaScript Training in Ambala ! Batra Computer Centre

Ending Statement with aSemicolon?

With traditional programming languages, like C++ and Java, each code statement has to end with a semicolon (;).

Many programmers continue this habit when writing JavaScript, but in general, semicolons are optional! However, semicolons are required if you want to put more than one statement on a single line.

Ph. No. :9729666670,4000670 Website: www.batracomputercentre.com

Page 8: JavaScript Training in Ambala ! Batra Computer Centre

Operators in

JavascriptThere are following important operators used in Javascripts:

Arithmetic Operator Assignment Operator Comparison Operator Logical Operator

Ph. No. :9729666670,4000670 Website: www.batracomputercentre.com

Page 9: JavaScript Training in Ambala ! Batra Computer Centre

Javascript Variables Variables are used to store data. A variable is a "container" for information you want

to store. A variable's value can change during the script. You can refer to a variable by name to see its value or to change its value.

Rules for variable names:• Variable names are case sensitive • They must begin with a letter or the underscore character

o strname – STRNAME (not same)

Ph. No. :9729666670,4000670 Website: www.batracomputercentre.com

Page 10: JavaScript Training in Ambala ! Batra Computer Centre

Arithmetic Operator Arithmetic operators are used to perform arithmetic

between variables and/or values. Given that y = 5, the table below explains the arithmetic

operators:– Addition– Subtraction– Multiplication– Division– Modulus– Increment– Decrement

Ph. No. :9729666670,4000670 Website: www.batracomputercentre.com

Page 11: JavaScript Training in Ambala ! Batra Computer Centre

Example

Ph. No. :9729666670,4000670 Website: www.batracomputercentre.com

Page 12: JavaScript Training in Ambala ! Batra Computer Centre

Assignment Operator

Assignment operators are used to assign values to JavaScript variables.

The basic assignment operator is equal (=), which assigns the value of its right operand to its left operand. That is, x = y assigns the value of y to x.

Given that x = 10 and y = 5, the table below explains the assignment operators:

Ph. No. :9729666670,4000670 Website: www.batracomputercentre.com

Page 13: JavaScript Training in Ambala ! Batra Computer Centre

Example

Ph. No. :9729666670,4000670 Website: www.batracomputercentre.com

Page 14: JavaScript Training in Ambala ! Batra Computer Centre

Comparison Operator Comparison operators are used in logical statements to

determine equality or difference between variables or values.

JavaScript has both strict and type–converting comparisons.

The more commonly-used abstract comparison (e.g. ==) converts the operands to the same type before making the comparison.

For relational abstract comparisons (e.g., <=), the operands are first converted to primitives, then to the same type, before comparison.

Ph. No. :9729666670,4000670 Website: www.batracomputercentre.com

Page 15: JavaScript Training in Ambala ! Batra Computer Centre

Example

Ph. No. :9729666670,4000670 Website: www.batracomputercentre.com

Page 16: JavaScript Training in Ambala ! Batra Computer Centre

Logical Operator

Logical operators are used to determine the logic between variables or values.

Logical operators are typically used with Boolean (logical) values.

However, the && and || operators actually return the value of one of the specified operands, so if these operators are used with non-Boolean values, they may return a non-Boolean value.

Ph. No. :9729666670,4000670 Website: www.batracomputercentre.com

Page 17: JavaScript Training in Ambala ! Batra Computer Centre

Example

Ph. No. :9729666670,4000670 Website: www.batracomputercentre.com

Page 18: JavaScript Training in Ambala ! Batra Computer Centre

Popup Boxes in Javascript

JavaScript has three kind of popup boxes: Alert box Confirm box Prompt box

Ph. No. :9729666670,4000670 Website: www.batracomputercentre.com

Page 19: JavaScript Training in Ambala ! Batra Computer Centre

Alert dailog Box

An alert dialog box is mostly used to give a warning message to the users. For example, if one input field requires to enter some text but the user does not provide any input, then as a part of validation, you can use an alert box to give a warning message.

Ph. No. :9729666670,4000670 Website: www.batracomputercentre.com

Page 20: JavaScript Training in Ambala ! Batra Computer Centre

Example

Ph. No. :9729666670,4000670 Website: www.batracomputercentre.com

Page 21: JavaScript Training in Ambala ! Batra Computer Centre

Output

Ph. No. :9729666670,4000670 Website: www.batracomputercentre.com

After click on “Click Me” =>

Page 22: JavaScript Training in Ambala ! Batra Computer Centre

Confirmation Dialog Box

A confirmation dialog box is mostly used to take user's consent on any option. It displays a dialog box with two buttons: Cancel.

If the user clicks on the OK button, the window method confirm() will return true. If the user clicks on the Cancel button, then confirm() returns false. You can use a confirmation dialog box as follows.

Ph. No. :9729666670,4000670 Website: www.batracomputercentre.com

Page 23: JavaScript Training in Ambala ! Batra Computer Centre

Example

Ph. No. :9729666670,4000670 Website: www.batracomputercentre.com

Page 24: JavaScript Training in Ambala ! Batra Computer Centre

Output

After click on “Click Me” =>

Ph. No. :9729666670,4000670 Website: www.batracomputercentre.com

Page 25: JavaScript Training in Ambala ! Batra Computer Centre

Prompt Dialog Box The prompt dialog box is very useful when you want to

pop-up a text box to get user input. Thus, it enables you to interact with the user. The user needs to fill in the field and then click OK.

This dialog box is displayed using a method called prompt() which takes two parameters: (i) a label which you want to display in the text box and (ii) a default string to display in the text box.

This dialog box has two buttons: OK and Cancel. If the user clicks the OK button, the window method prompt() will return the entered value from the text box.

If the user clicks the Cancel button, the window method prompt()returns null.

Ph. No. :9729666670,4000670 Website: www.batracomputercentre.com

Page 26: JavaScript Training in Ambala ! Batra Computer Centre

Example

Ph. No. :9729666670,4000670 Website: www.batracomputercentre.com

Page 27: JavaScript Training in Ambala ! Batra Computer Centre

Output

After click on “Click Me” =>

Ph. No. :9729666670,4000670 Website: www.batracomputercentre.com

Page 28: JavaScript Training in Ambala ! Batra Computer Centre

Ph. No. :9729666670,4000670 Website: www.batracomputercentre.com

Page 29: JavaScript Training in Ambala ! Batra Computer Centre

Ph. No. :9729666670,4000670 Website: www.batracomputercentre.com

CONTACT USBATRA COMPUTER CENTRE

SCO 15, Dayal Bagh, Near Hanuman Mandir, Ambala Cantt. Phn No.: 9729666670,0171-4000670 Email: [email protected] Website: www.batracomputercentre.com

Page 30: JavaScript Training in Ambala ! Batra Computer Centre

Ph. No. :9729666670,4000670 Website: www.batracomputercentre.com