SlideShare a Scribd company logo
Javascript
-Varsha Kumari
02/02/19 1
Introduction
• JavaScript is a front-end scripting language
developed by Netscape for dynamic content
– Lightweight, but with limited capabilities
– Can be used as object-oriented language
• Client-side technology
– Embedded in your HTML page
– Interpreted by the Web browser
• Simple and flexible
02/02/19 2
• HTML to define the content of web pages
• CSS to specify the layout of web pages
• JavaScript to program the dynamic behavior
of web pages
02/02/19 3
Using JavaScript Code
• The JavaScript code can be placed in:
– <script> tag in the head </script>
– <script> tag in the body </script>
– External files, linked via <script> tag in the head
• Files usually have .js extension
4
<script src="scripts.js" type="text/javscript"><script src="scripts.js" type="text/javscript">
</script></script>
The First Script
first-script.html
5
<html><html>
<body><body>
<script type="text/javascript"><script type="text/javascript">
alert('Hello JavaScript!');alert('Hello JavaScript!');
</script></script>
</body></body>
</html></html>
Another Small Example
small-example.html
6
<html><html>
<body><body>
<script type="text/javascript"><script type="text/javascript">
document.write('JavaScript rulez!');document.write('JavaScript rulez!');
</script></script>
</body></body>
</html></html>
<html><html>
<head><head>
<script type="text/javascript"><script type="text/javascript">
function test (message) {function test (message) {
alert(message);alert(message);
}}
</script></script>
</head></head>
<body><body>
<img src="logo.gif"<img src="logo.gif"
onclick="test('clicked!')" />onclick="test('clicked!')" />
</body></body>
</html></html>
Calling a JavaScript Function
from Event Handler –
Example
image-onclick.html
7
Using External Script Files• Using external script files:
External JavaScript file:
8
<html><html>
<head><head>
<script src="sample.js" type="text/javascript"><script src="sample.js" type="text/javascript">
</script></script>
</head></head>
<body><body>
<button onclick="sample()" value="Call JavaScript<button onclick="sample()" value="Call JavaScript
function from sample.js" />function from sample.js" />
</body></body>
</html></html>
function sample() {function sample() {
alert('Hello from sample.js!')alert('Hello from sample.js!')
external-JavaScript.htmlexternal-JavaScript.html
sample.jssample.js
The <script> tag is always empty.The <script> tag is always empty.
<script type = "text/JavaScript" language="JavaScript">
var a = "These sentence";
var italics_a = a.italics();
var b = "will continue over";
var upper_b = b.toUpperCase();
var c = "three variables";
var red_c = c.fontcolor("red");
var sentence = a+b+c;
var sentence_change = italics_a+upper_b+red_c;
document.write(sentence);
document.write("<br>");
document.write(sentence_change);
</script>
Standard Popup Boxes
• Alert box with text and [OK] button
– Just a message shown in a dialog box:
• Confirmation box
– Contains text, [OK] button and [Cancel] button:
• Prompt box
– Contains text, input field with default value:
10
alert("Some text here");alert("Some text here");
confirm("Are you sure?");confirm("Are you sure?");
prompt ("enter amount", 10);prompt ("enter amount", 10);
Alert Dialog Box
<html> <head>
<script type="text/javascript">
function Warn() {
alert ("This is a warning message!");
document.write ("This is a warning message!");
}
</script>
</head>
<body>
<p>Click the following button to see the result: </p>
<form> <input type="button" value="Click Me" onclick="Warn();" />
</form>
</body></html>
Confirmation Dialog Box
<html>
<head>
<script type="text/javascript">
function getConfirmation()
{
var retVal = confirm("Do you want to continue ?");
if( retVal == true )
{
document.write ("User wants to continue!");
return true;
}
Else
{ document.write ("User does not want to continue!");
return false; }
} </script> </head>
<body> <p>Click the following button to see the result: </p> <form>
<input type="button" value="Click Me" onclick="getConfirmation();" /> </form>
</body> </html>
Prompt Dialog Box
<html> <head>
<script type="text/javascript">
function getValue(){
var retVal = prompt("Enter your name : ", "your name here");
document.write("You have entered : " + retVal);
} </script> </head>
<body>
<p>Click the following button to see the result: </p>
<form>
<input type="button" value="Click Me" onclick="getValue();" />
</form>
</body></html>
JavaScript Syntax
• The JavaScript syntax is similar to Java
– Operators (+, *, =, !=, &&, ++, …)
– Variables (typeless)
– Conditional statements (if, else)
– Loops (for, while)
– Arrays (my_array[]) and associative arrays
(my_array['abc'])
– Functions (can return value)
14
Data Types
• JavaScript data types:
– Numbers (integer, floating-point)
– Boolean (true / false)
• String type – string of characters
• Arrays
• Associative arrays (hash tables)
15
var myName = "You can use both single or doublevar myName = "You can use both single or double
quotes for strings";quotes for strings";
var my_array = [1, 5.3, "aaa"];var my_array = [1, 5.3, "aaa"];
var my_hash = {a:2, b:3, c:"text"};var my_hash = {a:2, b:3, c:"text"};
Everything is Object• Every variable can be considered as object
– For example strings and arrays have member
functions:
16
var test = "some string";var test = "some string";
alert(test[7]); // shows letter 'r'alert(test[7]); // shows letter 'r'
alert(test.charAt(5)); // shows letter 's'alert(test.charAt(5)); // shows letter 's'
alert("test".charAt(1)); //shows letter 'e'alert("test".charAt(1)); //shows letter 'e'
alert("test".substring(1,3)); //shows 'esalert("test".substring(1,3)); //shows 'es''
var arr = [1,3,4];var arr = [1,3,4];
alert (arr.length); // shows 3alert (arr.length); // shows 3
arr.push(7); // appends 7 to end of arrayarr.push(7); // appends 7 to end of array
alert (arr[3]); // shows 7alert (arr[3]); // shows 7
objects.htmlobjects.html
String Operations
The + operator joins strings
• What is "9" + 9?
• Converting string to number:
17
string1 = "fat ";string1 = "fat ";
string2 = "cats";string2 = "cats";
alert(string1 + string2); // fat catsalert(string1 + string2); // fat cats
alert("9" + 9); // 99alert("9" + 9); // 99
alert(parseInt("9") + 9); // 18alert(parseInt("9") + 9); // 18
Sum of Numbers – Example
sum-of-numbers.html
18
<html><html>
<head><head>
<title>JavaScript Demo</title><title>JavaScript Demo</title>
<script type="text/javascript"><script type="text/javascript">
function calcSum() {function calcSum() {
value1 =value1 =
parseInt(document.mainForm.textBox1.value);parseInt(document.mainForm.textBox1.value);
value2 =value2 =
parseInt(document.mainForm.textBox2.value);parseInt(document.mainForm.textBox2.value);
sum = value1 + value2;sum = value1 + value2;
document.mainForm.textBoxSum.value = sum;document.mainForm.textBoxSum.value = sum;
}}
</script></script>
</head></head>
Sum of Numbers – Example (2)
sum-of-numbers.html (cont.)
19
<body><body>
<form name="mainForm"><form name="mainForm">
<input type="text" name="textBox1" /> <br/><input type="text" name="textBox1" /> <br/>
<input type="text" name="textBox2" /> <br/><input type="text" name="textBox2" /> <br/>
<input type="button" value="Process"<input type="button" value="Process"
onclick="javascript: calcSum()" />onclick="javascript: calcSum()" />
<input type="text" name="textBoxSum"<input type="text" name="textBoxSum"
readonly="readonly"/>readonly="readonly"/>
</form></form>
</body></body>
</html></html>
Form validation
<html><head>
<script>
function validateForm() {
var x = document.forms["myForm"]["fname"].value;
if (x == "") {
alert("Name must be filled out");
return false; }}
</script> </head>
<body>
<form name="myForm" action="/action_page.php" onsubmit="return
validateForm()" method="post">
Name: <input type="text" name="fname">
<input type="submit" value="Submit">
</form>
</body></html>
02/02/19 20
02/02/19 21

More Related Content

What's hot

Java Script
Java ScriptJava Script
Java Script
husbancom
 
Basics java scripts
Basics java scriptsBasics java scripts
Basics java scriptsch samaram
 
Introduction to java script
Introduction to java scriptIntroduction to java script
Introduction to java script
DivyaKS12
 
Web development basics (Part-4)
Web development basics (Part-4)Web development basics (Part-4)
Web development basics (Part-4)
Rajat Pratap Singh
 
Java scripts
Java scriptsJava scripts
Java scripts
Capgemini India
 
Introduction to Javascript By Satyen
Introduction to Javascript By  SatyenIntroduction to Javascript By  Satyen
Introduction to Javascript By Satyen
Satyen Pandya
 
Introduction to java script
Introduction to java scriptIntroduction to java script
Introduction to java script
nanjil1984
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
Marlon Jamera
 
Java script
Java scriptJava script
Java script
ITz_1
 
Javascript
JavascriptJavascript
Javascript
Nagarajan
 
Java script writing javascript
Java script writing javascriptJava script writing javascript
Java script writing javascriptJesus Obenita Jr.
 
10 Groovy Little JavaScript Tips
10 Groovy Little JavaScript Tips10 Groovy Little JavaScript Tips
10 Groovy Little JavaScript Tips
Troy Miles
 
1. java script language fundamentals
1. java script language fundamentals1. java script language fundamentals
1. java script language fundamentals
Rajiv Gupta
 
JavaScript Core fundamentals - Learn JavaScript Here
JavaScript Core fundamentals - Learn JavaScript HereJavaScript Core fundamentals - Learn JavaScript Here
JavaScript Core fundamentals - Learn JavaScript Here
Laurence Svekis ✔
 
Server Scripting Language -PHP
Server Scripting Language -PHPServer Scripting Language -PHP
Server Scripting Language -PHP
Deo Shao
 
JavaScript
JavaScriptJavaScript
JavaScript
Reem Alattas
 
Javascript Basics
Javascript BasicsJavascript Basics
Javascript Basics
Vishal Mittal
 
Seaside - Web Development As You Like It
Seaside - Web Development As You Like ItSeaside - Web Development As You Like It
Seaside - Web Development As You Like It
Lukas Renggli
 
Java script
Java scriptJava script
Java script
Sadeek Mohammed
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
Bhanuka Uyanage
 

What's hot (20)

Java Script
Java ScriptJava Script
Java Script
 
Basics java scripts
Basics java scriptsBasics java scripts
Basics java scripts
 
Introduction to java script
Introduction to java scriptIntroduction to java script
Introduction to java script
 
Web development basics (Part-4)
Web development basics (Part-4)Web development basics (Part-4)
Web development basics (Part-4)
 
Java scripts
Java scriptsJava scripts
Java scripts
 
Introduction to Javascript By Satyen
Introduction to Javascript By  SatyenIntroduction to Javascript By  Satyen
Introduction to Javascript By Satyen
 
Introduction to java script
Introduction to java scriptIntroduction to java script
Introduction to java script
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Java script
Java scriptJava script
Java script
 
Javascript
JavascriptJavascript
Javascript
 
Java script writing javascript
Java script writing javascriptJava script writing javascript
Java script writing javascript
 
10 Groovy Little JavaScript Tips
10 Groovy Little JavaScript Tips10 Groovy Little JavaScript Tips
10 Groovy Little JavaScript Tips
 
1. java script language fundamentals
1. java script language fundamentals1. java script language fundamentals
1. java script language fundamentals
 
JavaScript Core fundamentals - Learn JavaScript Here
JavaScript Core fundamentals - Learn JavaScript HereJavaScript Core fundamentals - Learn JavaScript Here
JavaScript Core fundamentals - Learn JavaScript Here
 
Server Scripting Language -PHP
Server Scripting Language -PHPServer Scripting Language -PHP
Server Scripting Language -PHP
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Javascript Basics
Javascript BasicsJavascript Basics
Javascript Basics
 
Seaside - Web Development As You Like It
Seaside - Web Development As You Like ItSeaside - Web Development As You Like It
Seaside - Web Development As You Like It
 
Java script
Java scriptJava script
Java script
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
 

Similar to Js mod1

JavaScript and jQuery Fundamentals
JavaScript and jQuery FundamentalsJavaScript and jQuery Fundamentals
JavaScript and jQuery FundamentalsBG Java EE Course
 
Wt unit 2 ppts client side technology
Wt unit 2 ppts client side technologyWt unit 2 ppts client side technology
Wt unit 2 ppts client side technology
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
FSJavaScript.ppt
FSJavaScript.pptFSJavaScript.ppt
FSJavaScript.ppt
AbhishekKumar66407
 
Java script
Java scriptJava script
Java script
Jay Patel
 
BITM3730 10-17.pptx
BITM3730 10-17.pptxBITM3730 10-17.pptx
BITM3730 10-17.pptx
MattMarino13
 
Javascript1
Javascript1Javascript1
Javascript1
anas Mohtaseb
 
Basics of Java Script (JS)
Basics of Java Script (JS)Basics of Java Script (JS)
Basics of Java Script (JS)
Ajay Khatri
 
JavaScript Training
JavaScript TrainingJavaScript Training
JavaScript Training
Ramindu Deshapriya
 
Javascript
JavascriptJavascript
Javascript
D V BHASKAR REDDY
 
2013-06-25 - HTML5 & JavaScript Security
2013-06-25 - HTML5 & JavaScript Security2013-06-25 - HTML5 & JavaScript Security
2013-06-25 - HTML5 & JavaScript Security
Johannes Hoppe
 
Jscript Fundamentals
Jscript FundamentalsJscript Fundamentals
Jscript Fundamentalsrspaike
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypesVarun C M
 
IT2255 Web Essentials - Unit III Client-Side Processing and Scripting
IT2255 Web Essentials - Unit III Client-Side Processing and ScriptingIT2255 Web Essentials - Unit III Client-Side Processing and Scripting
IT2255 Web Essentials - Unit III Client-Side Processing and Scripting
pkaviya
 
Java script
Java scriptJava script
Java script
Soham Sengupta
 
Java script
 Java script Java script
Java scriptbosybosy
 
Java script
Java scriptJava script
Java script
Ravinder Kamboj
 

Similar to Js mod1 (20)

JavaScript and jQuery Fundamentals
JavaScript and jQuery FundamentalsJavaScript and jQuery Fundamentals
JavaScript and jQuery Fundamentals
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Wt unit 2 ppts client side technology
Wt unit 2 ppts client side technologyWt unit 2 ppts client side technology
Wt unit 2 ppts client side technology
 
Wt unit 2 ppts client sied technology
Wt unit 2 ppts client sied technologyWt unit 2 ppts client sied technology
Wt unit 2 ppts client sied technology
 
FSJavaScript.ppt
FSJavaScript.pptFSJavaScript.ppt
FSJavaScript.ppt
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Java script
Java scriptJava script
Java script
 
BITM3730 10-17.pptx
BITM3730 10-17.pptxBITM3730 10-17.pptx
BITM3730 10-17.pptx
 
Javascript1
Javascript1Javascript1
Javascript1
 
Basics of Java Script (JS)
Basics of Java Script (JS)Basics of Java Script (JS)
Basics of Java Script (JS)
 
JavaScript Training
JavaScript TrainingJavaScript Training
JavaScript Training
 
Javascript
JavascriptJavascript
Javascript
 
2013-06-25 - HTML5 & JavaScript Security
2013-06-25 - HTML5 & JavaScript Security2013-06-25 - HTML5 & JavaScript Security
2013-06-25 - HTML5 & JavaScript Security
 
Jscript Fundamentals
Jscript FundamentalsJscript Fundamentals
Jscript Fundamentals
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
 
IT2255 Web Essentials - Unit III Client-Side Processing and Scripting
IT2255 Web Essentials - Unit III Client-Side Processing and ScriptingIT2255 Web Essentials - Unit III Client-Side Processing and Scripting
IT2255 Web Essentials - Unit III Client-Side Processing and Scripting
 
Java script
Java scriptJava script
Java script
 
Java script
 Java script Java script
Java script
 
Java script
Java scriptJava script
Java script
 
Unit 2.4
Unit 2.4Unit 2.4
Unit 2.4
 

More from VARSHAKUMARI49

28,29. procedures subprocedure,type checking functions in VBScript
28,29. procedures  subprocedure,type checking functions in VBScript28,29. procedures  subprocedure,type checking functions in VBScript
28,29. procedures subprocedure,type checking functions in VBScript
VARSHAKUMARI49
 
30,31,32,33. decision and loop statements in vbscript
30,31,32,33. decision and loop statements in vbscript30,31,32,33. decision and loop statements in vbscript
30,31,32,33. decision and loop statements in vbscript
VARSHAKUMARI49
 
27. mathematical, date and time functions in VB Script
27. mathematical, date and time  functions in VB Script27. mathematical, date and time  functions in VB Script
27. mathematical, date and time functions in VB Script
VARSHAKUMARI49
 
Cascading style sheet
Cascading style sheetCascading style sheet
Cascading style sheet
VARSHAKUMARI49
 
Html
HtmlHtml
Introduction to web technology
Introduction to web technologyIntroduction to web technology
Introduction to web technology
VARSHAKUMARI49
 
Database normalization
Database normalizationDatabase normalization
Database normalization
VARSHAKUMARI49
 
Joins
JoinsJoins
Sub queries
Sub queriesSub queries
Sub queries
VARSHAKUMARI49
 
Introduction to sql
Introduction to sqlIntroduction to sql
Introduction to sql
VARSHAKUMARI49
 
Css module1
Css module1Css module1
Css module1
VARSHAKUMARI49
 
Css mod1
Css mod1Css mod1
Css mod1
VARSHAKUMARI49
 
Html mod1
Html mod1Html mod1
Html mod1
VARSHAKUMARI49
 
Register counters.readonly
Register counters.readonlyRegister counters.readonly
Register counters.readonly
VARSHAKUMARI49
 
Sorting.ppt read only
Sorting.ppt read onlySorting.ppt read only
Sorting.ppt read only
VARSHAKUMARI49
 
Hashing
HashingHashing

More from VARSHAKUMARI49 (16)

28,29. procedures subprocedure,type checking functions in VBScript
28,29. procedures  subprocedure,type checking functions in VBScript28,29. procedures  subprocedure,type checking functions in VBScript
28,29. procedures subprocedure,type checking functions in VBScript
 
30,31,32,33. decision and loop statements in vbscript
30,31,32,33. decision and loop statements in vbscript30,31,32,33. decision and loop statements in vbscript
30,31,32,33. decision and loop statements in vbscript
 
27. mathematical, date and time functions in VB Script
27. mathematical, date and time  functions in VB Script27. mathematical, date and time  functions in VB Script
27. mathematical, date and time functions in VB Script
 
Cascading style sheet
Cascading style sheetCascading style sheet
Cascading style sheet
 
Html
HtmlHtml
Html
 
Introduction to web technology
Introduction to web technologyIntroduction to web technology
Introduction to web technology
 
Database normalization
Database normalizationDatabase normalization
Database normalization
 
Joins
JoinsJoins
Joins
 
Sub queries
Sub queriesSub queries
Sub queries
 
Introduction to sql
Introduction to sqlIntroduction to sql
Introduction to sql
 
Css module1
Css module1Css module1
Css module1
 
Css mod1
Css mod1Css mod1
Css mod1
 
Html mod1
Html mod1Html mod1
Html mod1
 
Register counters.readonly
Register counters.readonlyRegister counters.readonly
Register counters.readonly
 
Sorting.ppt read only
Sorting.ppt read onlySorting.ppt read only
Sorting.ppt read only
 
Hashing
HashingHashing
Hashing
 

Recently uploaded

6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
ongomchris
 
Basic Industrial Engineering terms for apparel
Basic Industrial Engineering terms for apparelBasic Industrial Engineering terms for apparel
Basic Industrial Engineering terms for apparel
top1002
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
manasideore6
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
BrazilAccount1
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
BrazilAccount1
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
ssuser7dcef0
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
aqil azizi
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
WENKENLI1
 

Recently uploaded (20)

6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
 
Basic Industrial Engineering terms for apparel
Basic Industrial Engineering terms for apparelBasic Industrial Engineering terms for apparel
Basic Industrial Engineering terms for apparel
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
 

Js mod1

  • 2. Introduction • JavaScript is a front-end scripting language developed by Netscape for dynamic content – Lightweight, but with limited capabilities – Can be used as object-oriented language • Client-side technology – Embedded in your HTML page – Interpreted by the Web browser • Simple and flexible 02/02/19 2
  • 3. • HTML to define the content of web pages • CSS to specify the layout of web pages • JavaScript to program the dynamic behavior of web pages 02/02/19 3
  • 4. Using JavaScript Code • The JavaScript code can be placed in: – <script> tag in the head </script> – <script> tag in the body </script> – External files, linked via <script> tag in the head • Files usually have .js extension 4 <script src="scripts.js" type="text/javscript"><script src="scripts.js" type="text/javscript"> </script></script>
  • 5. The First Script first-script.html 5 <html><html> <body><body> <script type="text/javascript"><script type="text/javascript"> alert('Hello JavaScript!');alert('Hello JavaScript!'); </script></script> </body></body> </html></html>
  • 6. Another Small Example small-example.html 6 <html><html> <body><body> <script type="text/javascript"><script type="text/javascript"> document.write('JavaScript rulez!');document.write('JavaScript rulez!'); </script></script> </body></body> </html></html>
  • 7. <html><html> <head><head> <script type="text/javascript"><script type="text/javascript"> function test (message) {function test (message) { alert(message);alert(message); }} </script></script> </head></head> <body><body> <img src="logo.gif"<img src="logo.gif" onclick="test('clicked!')" />onclick="test('clicked!')" /> </body></body> </html></html> Calling a JavaScript Function from Event Handler – Example image-onclick.html 7
  • 8. Using External Script Files• Using external script files: External JavaScript file: 8 <html><html> <head><head> <script src="sample.js" type="text/javascript"><script src="sample.js" type="text/javascript"> </script></script> </head></head> <body><body> <button onclick="sample()" value="Call JavaScript<button onclick="sample()" value="Call JavaScript function from sample.js" />function from sample.js" /> </body></body> </html></html> function sample() {function sample() { alert('Hello from sample.js!')alert('Hello from sample.js!') external-JavaScript.htmlexternal-JavaScript.html sample.jssample.js The <script> tag is always empty.The <script> tag is always empty.
  • 9. <script type = "text/JavaScript" language="JavaScript"> var a = "These sentence"; var italics_a = a.italics(); var b = "will continue over"; var upper_b = b.toUpperCase(); var c = "three variables"; var red_c = c.fontcolor("red"); var sentence = a+b+c; var sentence_change = italics_a+upper_b+red_c; document.write(sentence); document.write("<br>"); document.write(sentence_change); </script>
  • 10. Standard Popup Boxes • Alert box with text and [OK] button – Just a message shown in a dialog box: • Confirmation box – Contains text, [OK] button and [Cancel] button: • Prompt box – Contains text, input field with default value: 10 alert("Some text here");alert("Some text here"); confirm("Are you sure?");confirm("Are you sure?"); prompt ("enter amount", 10);prompt ("enter amount", 10);
  • 11. Alert Dialog Box <html> <head> <script type="text/javascript"> function Warn() { alert ("This is a warning message!"); document.write ("This is a warning message!"); } </script> </head> <body> <p>Click the following button to see the result: </p> <form> <input type="button" value="Click Me" onclick="Warn();" /> </form> </body></html>
  • 12. Confirmation Dialog Box <html> <head> <script type="text/javascript"> function getConfirmation() { var retVal = confirm("Do you want to continue ?"); if( retVal == true ) { document.write ("User wants to continue!"); return true; } Else { document.write ("User does not want to continue!"); return false; } } </script> </head> <body> <p>Click the following button to see the result: </p> <form> <input type="button" value="Click Me" onclick="getConfirmation();" /> </form> </body> </html>
  • 13. Prompt Dialog Box <html> <head> <script type="text/javascript"> function getValue(){ var retVal = prompt("Enter your name : ", "your name here"); document.write("You have entered : " + retVal); } </script> </head> <body> <p>Click the following button to see the result: </p> <form> <input type="button" value="Click Me" onclick="getValue();" /> </form> </body></html>
  • 14. JavaScript Syntax • The JavaScript syntax is similar to Java – Operators (+, *, =, !=, &&, ++, …) – Variables (typeless) – Conditional statements (if, else) – Loops (for, while) – Arrays (my_array[]) and associative arrays (my_array['abc']) – Functions (can return value) 14
  • 15. Data Types • JavaScript data types: – Numbers (integer, floating-point) – Boolean (true / false) • String type – string of characters • Arrays • Associative arrays (hash tables) 15 var myName = "You can use both single or doublevar myName = "You can use both single or double quotes for strings";quotes for strings"; var my_array = [1, 5.3, "aaa"];var my_array = [1, 5.3, "aaa"]; var my_hash = {a:2, b:3, c:"text"};var my_hash = {a:2, b:3, c:"text"};
  • 16. Everything is Object• Every variable can be considered as object – For example strings and arrays have member functions: 16 var test = "some string";var test = "some string"; alert(test[7]); // shows letter 'r'alert(test[7]); // shows letter 'r' alert(test.charAt(5)); // shows letter 's'alert(test.charAt(5)); // shows letter 's' alert("test".charAt(1)); //shows letter 'e'alert("test".charAt(1)); //shows letter 'e' alert("test".substring(1,3)); //shows 'esalert("test".substring(1,3)); //shows 'es'' var arr = [1,3,4];var arr = [1,3,4]; alert (arr.length); // shows 3alert (arr.length); // shows 3 arr.push(7); // appends 7 to end of arrayarr.push(7); // appends 7 to end of array alert (arr[3]); // shows 7alert (arr[3]); // shows 7 objects.htmlobjects.html
  • 17. String Operations The + operator joins strings • What is "9" + 9? • Converting string to number: 17 string1 = "fat ";string1 = "fat "; string2 = "cats";string2 = "cats"; alert(string1 + string2); // fat catsalert(string1 + string2); // fat cats alert("9" + 9); // 99alert("9" + 9); // 99 alert(parseInt("9") + 9); // 18alert(parseInt("9") + 9); // 18
  • 18. Sum of Numbers – Example sum-of-numbers.html 18 <html><html> <head><head> <title>JavaScript Demo</title><title>JavaScript Demo</title> <script type="text/javascript"><script type="text/javascript"> function calcSum() {function calcSum() { value1 =value1 = parseInt(document.mainForm.textBox1.value);parseInt(document.mainForm.textBox1.value); value2 =value2 = parseInt(document.mainForm.textBox2.value);parseInt(document.mainForm.textBox2.value); sum = value1 + value2;sum = value1 + value2; document.mainForm.textBoxSum.value = sum;document.mainForm.textBoxSum.value = sum; }} </script></script> </head></head>
  • 19. Sum of Numbers – Example (2) sum-of-numbers.html (cont.) 19 <body><body> <form name="mainForm"><form name="mainForm"> <input type="text" name="textBox1" /> <br/><input type="text" name="textBox1" /> <br/> <input type="text" name="textBox2" /> <br/><input type="text" name="textBox2" /> <br/> <input type="button" value="Process"<input type="button" value="Process" onclick="javascript: calcSum()" />onclick="javascript: calcSum()" /> <input type="text" name="textBoxSum"<input type="text" name="textBoxSum" readonly="readonly"/>readonly="readonly"/> </form></form> </body></body> </html></html>
  • 20. Form validation <html><head> <script> function validateForm() { var x = document.forms["myForm"]["fname"].value; if (x == "") { alert("Name must be filled out"); return false; }} </script> </head> <body> <form name="myForm" action="/action_page.php" onsubmit="return validateForm()" method="post"> Name: <input type="text" name="fname"> <input type="submit" value="Submit"> </form> </body></html> 02/02/19 20