SlideShare a Scribd company logo
www.SunilOS.com 1
www.sunilos.com
www.raystec.com
JavaScript
Hello.html
<HTML>
<HEAD></HEAD>
<BODY>
<center><b><u>
Hello
</u></b></center>
</BODY>
</HTML>
www.SunilOS.com 2
Submit Data From HTML Form
<HTML>
<HEAD></HEAD>
<BODY>
<FORM METHOD=“GET” ACTION="HelloName.jsp">
Enter Name
<INPUT TYPE="text" NAME="fName">
<INPUT VALUE="GO" TYPE="submit">
</FORM>
</BODY>
</HTML>
GET
POST
On Submit -
http://localhost:8080/aajkiapp/HelloName.jsp?fName=Sunrays
www.SunilOS.com 3
FORM Fields
 <FORM METHOD=GET ACTION="">
 Text Field<INPUT TYPE="text" NAME="userId"><BR>
 Password Field<INPUT TYPE="password" NAME ="pwd"><BR>
 Checkbox Field<INPUT TYPE="checkbox" NAME="checkBox"
VALUE="1" ><BR>
 Radio Field<INPUT TYPE="radio" NAME="degree" VALUE="MCA">
 <INPUT TYPE="radio" NAME="degree" VALUE="BE"><BR>
 Button <INPUT TYPE="button" NAME="action" VALUE="Go"><BR>
 Submit Button<INPUT TYPE="Submit" VALUE="Submit"><BR>
www.SunilOS.com 4
FORM Fields (Cont.)
 Reset Button<INPUT TYPE="reset" VALUE="Clear"><BR>
 TextArea<TEXTAREA NAME="tArea" ROWS="2"
COLS="20"></TEXTAREA><BR>
 List <SELECT NAME="list">
 <OPTION VALUE="1">ONE</OPTION>
 <OPTION VALUE="2">TWO</OPTION>
 </SELECT><BR>
 Hidden Value<INPUT TYPE="hidden" NAME="id"
VALUE="123">
 </FORM>
www.SunilOS.com 5
FORM Fields
www.SunilOS.com 6
JavaScript
It is the scripting language of the Web.
It is used in millions of Web pages to add
functionalities:
o Validate forms
o Detect browsers
o Handle Cookies
..and much more
www.SunilOS.com 7
<script> Tag
 <HTML>
 <HEAD>
o <SCRIPT LANGUAGE="JavaScript">
o function hello(){
o alert(“Pahala Pahala Click");
o }
o </SCRIPT>
 </HEAD>
 <input name="operation" type="button" value="Click Me"
 onclick="hello()" >
www.SunilOS.com 8
Key points
 Javascript functions are written in script tag.
o <script language="text/javascript">…</script>
 Tag <script > can be written anywhere in HTML but
<HEAD> tag is preferred to write it because head position
is first loaded in browser.
 Function is always started with 'function' key word.
 Variables are defined by optional 'var' keyword. For
example
o var msg =0; //with var
o OR
o msg=0; //witout var
www.SunilOS.com 9
Key points (Cont.)
 Data type of a variable is depending on its stored
value.
o var num= 1; //integer
o var name ="sunrays“; //string
o var salary = 1.5; //float
 String can be represented by single quote (') or
double quote (") in Javascript.
o var org = “sunrays”;
o var org = 'sunrays' ;
www.SunilOS.com 10
<INPUT event
Attribute The event occurs when...
onabort Loading of an image is interrupted
onblur An element loses focus
onchange The user changes the content of a field
onclick Mouse clicks an object
ondblclick Mouse double-clicks an object
onerror An error occurs when loading a document or an image
onfocus An element gets focus
onkeydown A keyboard key is pressed
onkeypress A keyboard key is pressed or held down
onkeyup A keyboard key is released
onload A page or an image is finished loading
www.SunilOS.com 11
Javascript Objects
 <HTML>
 <HEAD></HEAD>
 <BODY>
 <FORM NAME=‘helloForm’ METHOD=“GET”
ACTION="HelloName.jsp">
o Enter Name
o <INPUT TYPE="text" NAME=“name“ VALUE=‘XYZ’>
 <INPUT VALUE="GO" TYPE="submit">
 </FORM>
 </BODY>
 </HTML>
document
form
name
alert(document.helloForm.name.value);
www.SunilOS.com 12
Confirm Box (Are You Sure) ?
<form action="Abc.jsp">
Roll NO <input type="text" name="rollNo">
<input name="operation" type="button"
value="Delete“ onclick="doDelete(this.form)" >
</form>
www.SunilOS.com 13
Confirm Box ( Cont.)
 <script type="text/javascript">
 function doDelete(frm){

 if(frm.rollNo.value == ''){
 alert("Roll number can not be null")
 frm.rollNo.focus();
 }else {
 var flag = confirm("Are you sure ?");
 if(flag){
 frm.submit();
 }
 }
 }
 </script>
www.SunilOS.com 14
Sum of two Numbers
 <form name=“calForm” >
 <input type="text" name="num1">+
 <input type="text" name="num2">=
 <input type="text" name="sum" readonly=“true">
 <input type="button" value="Calculate" onclick="calc(document.calForm)"
>
 <input type="button" value="Calculate“ onclick="calc(this.form)" >
 </form>
www.SunilOS.com 15
Sum of two Numbers
 <form action="">
 <input type="text" name="num1“ onchange="calc(this.form)" >
 + <input type="text" name="num2“ onchange="calc(this.form)" >
 = <input type="text" name="sum" readonly=“true">
 <input type="button" value="Calculate" onclick="calc(this.form)" >
 </form>
www.SunilOS.com 16
Calculate Sum
<script type="text/javascript">
function calc(frm){
 var n1 = parseInt(frm.num1.value);
 var n2 = parseInt(frm.num2.value);
 frm.sum.value = n1 + n2;
 return frm.sum.value;
}
</script>
www.SunilOS.com 17
Validation on form submit
<form onsubmit="return validate(this)">
o User ID <input type="text" name="id"><br>
o Password <input type=“text" name="pwd">
o <input type="submit" value=“Go" >
</form>
www.SunilOS.com 18
Validate method
 function validate(frm){

 var flag = true;
 if(frm.id.value == ''){
 alert("User ID can not be null");
 flag = false;
 }
 if(frm.pwd.value == ''){
 alert("Password can not be null");
 flag = false;
 }
 return flag;
 }
www.SunilOS.com 19
Reusable functions .js file
Reusable functions can be stored in a text file that
has extension .js.
HTML pages can import functions from a .js file to
use them.
HTML pages can import multiple .js files.
Include .js files into HTML by <script> tag:
o <script type="text/javascript" src="menu.js">
o <script type="text/javascript" src=“calendar.js">
www.SunilOS.com 20
Javascript Frameworks
JQuery
Angular JS
Ext JS
Prototype
DOJO
www.SunilOS.com 21
AJAX
 Asynchronous JavaScript and XML
 HTML pages call a web resource (web page)
asynchronously (in the background) without impacting
existing displaying page.
 HTML pages can send and receive data with the help of
AJAX from the source server asynchronously.
 Object XMLHttpRequest is used to make asynchronous
calls.
 Usually JSON data fetched by AJAX calls.
www.SunilOS.com 22
Get XmlHttpObject
 function getXmlHttpObject(){
 var xmlHttp=null;
 try{
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
 catch (e){
 // Internet Explorer
 try{
 xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
 }
 catch (e){
 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
 }
 }
 return xmlHttp;
 }
www.SunilOS.com 23
HTML
 Sign Up Guest :
 <INPUT TYPE="radio“ NAME="site“ onClick="getContent(‘/App/Guest')">
 Sign Up Patient:
 <INPUT TYPE="radio" NAME="site“ onClick="getContent('/App/Patient')">
 Sign Up Doctor:
 <INPUT TYPE="radio" NAME="site“ onClick="getContent('/App/Doctor')" >
 <TD id='bodyText'> AJAX Text will be replaced here </TD>
www.SunilOS.com 24
Get Data
 function getContent(url){
o var xmlHttp = getXmlHttpObject();
o xmlHttp.open("GET",url,true);
o //attach function
o xmlHttp.onreadystatechange=function(){
 if(xmlHttp.readyState==4 && xmlHttp.status == 200) {
• var cont = xmlHttp.responseText;
• document.getElementById('bodyText').innerHTML = cont;
 }
o }
o xmlHttp.send(null);
 }
www.SunilOS.com 25
Disclaimer
This is an educational presentation to enhance the
skill of computer science students.
This presentation is available for free to computer
science students.
Some internet images from different URLs are
used in this presentation to simplify technical
examples and correlate examples with the real
world.
We are grateful to owners of these URLs and
pictures.
www.SunilOS.com 26
Thank You!
www.SunilOS.com 27
www.SunilOS.com
Ad

More Related Content

What's hot (20)

Log4 J
Log4 JLog4 J
Log4 J
Sunil OS
 
Java 8 - CJ
Java 8 - CJJava 8 - CJ
Java 8 - CJ
Sunil OS
 
PDBC
PDBCPDBC
PDBC
Sunil OS
 
Threads V4
Threads  V4Threads  V4
Threads V4
Sunil OS
 
Java IO Streams V4
Java IO Streams V4Java IO Streams V4
Java IO Streams V4
Sunil OS
 
JUnit 4
JUnit 4JUnit 4
JUnit 4
Sunil OS
 
Resource Bundle
Resource BundleResource Bundle
Resource Bundle
Sunil OS
 
Collections Framework
Collections FrameworkCollections Framework
Collections Framework
Sunil OS
 
DJango
DJangoDJango
DJango
Sunil OS
 
JAVA OOP
JAVA OOPJAVA OOP
JAVA OOP
Sunil OS
 
Java Basics
Java BasicsJava Basics
Java Basics
Sunil OS
 
JAVA Variables and Operators
JAVA Variables and OperatorsJAVA Variables and Operators
JAVA Variables and Operators
Sunil OS
 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File Handling
Sunil OS
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
Amit Tyagi
 
Python part2 v1
Python part2 v1Python part2 v1
Python part2 v1
Sunil OS
 
Python Part 1
Python Part 1Python Part 1
Python Part 1
Sunil OS
 
Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript
Bala Narayanan
 
C Basics
C BasicsC Basics
C Basics
Sunil OS
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript Tutorial
Bui Kiet
 
3. Java Script
3. Java Script3. Java Script
3. Java Script
Jalpesh Vasa
 
Java 8 - CJ
Java 8 - CJJava 8 - CJ
Java 8 - CJ
Sunil OS
 
Threads V4
Threads  V4Threads  V4
Threads V4
Sunil OS
 
Java IO Streams V4
Java IO Streams V4Java IO Streams V4
Java IO Streams V4
Sunil OS
 
Resource Bundle
Resource BundleResource Bundle
Resource Bundle
Sunil OS
 
Collections Framework
Collections FrameworkCollections Framework
Collections Framework
Sunil OS
 
Java Basics
Java BasicsJava Basics
Java Basics
Sunil OS
 
JAVA Variables and Operators
JAVA Variables and OperatorsJAVA Variables and Operators
JAVA Variables and Operators
Sunil OS
 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File Handling
Sunil OS
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
Amit Tyagi
 
Python part2 v1
Python part2 v1Python part2 v1
Python part2 v1
Sunil OS
 
Python Part 1
Python Part 1Python Part 1
Python Part 1
Sunil OS
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript Tutorial
Bui Kiet
 

Viewers also liked (10)

C# Variables and Operators
C# Variables and OperatorsC# Variables and Operators
C# Variables and Operators
Sunil OS
 
Java Threads and Concurrency
Java Threads and ConcurrencyJava Threads and Concurrency
Java Threads and Concurrency
Sunil OS
 
Javascript - Numbers
Javascript   - NumbersJavascript   - Numbers
Javascript - Numbers
Samuel Santos
 
Java script basic
Java script basicJava script basic
Java script basic
Ravi Bhadauria
 
Rays Technologies
Rays TechnologiesRays Technologies
Rays Technologies
Sunil OS
 
C++
C++C++
C++
Sunil OS
 
C# Basics
C# BasicsC# Basics
C# Basics
Sunil OS
 
C++ oop
C++ oopC++ oop
C++ oop
Sunil OS
 
Java Swing JFC
Java Swing JFCJava Swing JFC
Java Swing JFC
Sunil OS
 
Eschool erp School Management System SMS System School Software
Eschool erp School Management System SMS System School SoftwareEschool erp School Management System SMS System School Software
Eschool erp School Management System SMS System School Software
Mayank Jain
 
C# Variables and Operators
C# Variables and OperatorsC# Variables and Operators
C# Variables and Operators
Sunil OS
 
Java Threads and Concurrency
Java Threads and ConcurrencyJava Threads and Concurrency
Java Threads and Concurrency
Sunil OS
 
Javascript - Numbers
Javascript   - NumbersJavascript   - Numbers
Javascript - Numbers
Samuel Santos
 
Rays Technologies
Rays TechnologiesRays Technologies
Rays Technologies
Sunil OS
 
Java Swing JFC
Java Swing JFCJava Swing JFC
Java Swing JFC
Sunil OS
 
Eschool erp School Management System SMS System School Software
Eschool erp School Management System SMS System School SoftwareEschool erp School Management System SMS System School Software
Eschool erp School Management System SMS System School Software
Mayank Jain
 
Ad

Similar to JavaScript (20)

Internet and Web Technology (CLASS-8) [jQuery and JSON] | NIC/NIELIT Web Tech...
Internet and Web Technology (CLASS-8) [jQuery and JSON] | NIC/NIELIT Web Tech...Internet and Web Technology (CLASS-8) [jQuery and JSON] | NIC/NIELIT Web Tech...
Internet and Web Technology (CLASS-8) [jQuery and JSON] | NIC/NIELIT Web Tech...
Ayes Chinmay
 
Introduction to Html5
Introduction to Html5Introduction to Html5
Introduction to Html5
www.netgains.org
 
Week 4 - jQuery + Ajax
Week 4 - jQuery + AjaxWeek 4 - jQuery + Ajax
Week 4 - jQuery + Ajax
baygross
 
lec 14-15 Jquery_All About J-query_.pptx
lec 14-15 Jquery_All About J-query_.pptxlec 14-15 Jquery_All About J-query_.pptx
lec 14-15 Jquery_All About J-query_.pptx
MuhammadAbubakar114879
 
A Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NETA Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NET
James Johnson
 
Javascript 2
Javascript 2Javascript 2
Javascript 2
pavishkumarsingh
 
J query training
J query trainingJ query training
J query training
FIS - Fidelity Information Services
 
HTML5 New and Improved
HTML5   New and ImprovedHTML5   New and Improved
HTML5 New and Improved
Timothy Fisher
 
lect4
lect4lect4
lect4
tutorialsruby
 
lect4
lect4lect4
lect4
tutorialsruby
 
Python Code Camp for Professionals 1/4
Python Code Camp for Professionals 1/4Python Code Camp for Professionals 1/4
Python Code Camp for Professionals 1/4
DEVCON
 
HTML5 - The 2012 of the Web
HTML5 - The 2012 of the WebHTML5 - The 2012 of the Web
HTML5 - The 2012 of the Web
Robert Nyman
 
HTML5 - The 2012 of the Web - Adobe MAX
HTML5 - The 2012 of the Web - Adobe MAXHTML5 - The 2012 of the Web - Adobe MAX
HTML5 - The 2012 of the Web - Adobe MAX
Robert Nyman
 
JSP
JSPJSP
JSP
corneliuskoo
 
Java script Advance
Java script   AdvanceJava script   Advance
Java script Advance
Jaya Kumari
 
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCBackbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVC
pootsbook
 
Practica n° 7
Practica n° 7Practica n° 7
Practica n° 7
rafobarrientos
 
Client Web
Client WebClient Web
Client Web
Markiyan Matsekh
 
Building iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoBuilding iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" Domino
Rob Bontekoe
 
jQuery Fundamentals
jQuery FundamentalsjQuery Fundamentals
jQuery Fundamentals
Gil Fink
 
Internet and Web Technology (CLASS-8) [jQuery and JSON] | NIC/NIELIT Web Tech...
Internet and Web Technology (CLASS-8) [jQuery and JSON] | NIC/NIELIT Web Tech...Internet and Web Technology (CLASS-8) [jQuery and JSON] | NIC/NIELIT Web Tech...
Internet and Web Technology (CLASS-8) [jQuery and JSON] | NIC/NIELIT Web Tech...
Ayes Chinmay
 
Week 4 - jQuery + Ajax
Week 4 - jQuery + AjaxWeek 4 - jQuery + Ajax
Week 4 - jQuery + Ajax
baygross
 
lec 14-15 Jquery_All About J-query_.pptx
lec 14-15 Jquery_All About J-query_.pptxlec 14-15 Jquery_All About J-query_.pptx
lec 14-15 Jquery_All About J-query_.pptx
MuhammadAbubakar114879
 
A Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NETA Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NET
James Johnson
 
HTML5 New and Improved
HTML5   New and ImprovedHTML5   New and Improved
HTML5 New and Improved
Timothy Fisher
 
Python Code Camp for Professionals 1/4
Python Code Camp for Professionals 1/4Python Code Camp for Professionals 1/4
Python Code Camp for Professionals 1/4
DEVCON
 
HTML5 - The 2012 of the Web
HTML5 - The 2012 of the WebHTML5 - The 2012 of the Web
HTML5 - The 2012 of the Web
Robert Nyman
 
HTML5 - The 2012 of the Web - Adobe MAX
HTML5 - The 2012 of the Web - Adobe MAXHTML5 - The 2012 of the Web - Adobe MAX
HTML5 - The 2012 of the Web - Adobe MAX
Robert Nyman
 
Java script Advance
Java script   AdvanceJava script   Advance
Java script Advance
Jaya Kumari
 
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCBackbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVC
pootsbook
 
Building iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoBuilding iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" Domino
Rob Bontekoe
 
jQuery Fundamentals
jQuery FundamentalsjQuery Fundamentals
jQuery Fundamentals
Gil Fink
 
Ad

More from Sunil OS (8)

OOP v3
OOP v3OOP v3
OOP v3
Sunil OS
 
Threads v3
Threads v3Threads v3
Threads v3
Sunil OS
 
Exception Handling v3
Exception Handling v3Exception Handling v3
Exception Handling v3
Sunil OS
 
Machine learning ( Part 3 )
Machine learning ( Part 3 )Machine learning ( Part 3 )
Machine learning ( Part 3 )
Sunil OS
 
Machine learning ( Part 2 )
Machine learning ( Part 2 )Machine learning ( Part 2 )
Machine learning ( Part 2 )
Sunil OS
 
Machine learning ( Part 1 )
Machine learning ( Part 1 )Machine learning ( Part 1 )
Machine learning ( Part 1 )
Sunil OS
 
Python Pandas
Python PandasPython Pandas
Python Pandas
Sunil OS
 
Angular 8
Angular 8 Angular 8
Angular 8
Sunil OS
 
Threads v3
Threads v3Threads v3
Threads v3
Sunil OS
 
Exception Handling v3
Exception Handling v3Exception Handling v3
Exception Handling v3
Sunil OS
 
Machine learning ( Part 3 )
Machine learning ( Part 3 )Machine learning ( Part 3 )
Machine learning ( Part 3 )
Sunil OS
 
Machine learning ( Part 2 )
Machine learning ( Part 2 )Machine learning ( Part 2 )
Machine learning ( Part 2 )
Sunil OS
 
Machine learning ( Part 1 )
Machine learning ( Part 1 )Machine learning ( Part 1 )
Machine learning ( Part 1 )
Sunil OS
 
Python Pandas
Python PandasPython Pandas
Python Pandas
Sunil OS
 
Angular 8
Angular 8 Angular 8
Angular 8
Sunil OS
 

Recently uploaded (20)

CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptx
milanasargsyan5
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
Diabetic neuropathy peripheral autonomic
Diabetic neuropathy peripheral autonomicDiabetic neuropathy peripheral autonomic
Diabetic neuropathy peripheral autonomic
Pankaj Patawari
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
Timber Pitch Roof Construction Measurement-2024.pptx
Timber Pitch Roof Construction Measurement-2024.pptxTimber Pitch Roof Construction Measurement-2024.pptx
Timber Pitch Roof Construction Measurement-2024.pptx
Tantish QS, UTM
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Fundamentals of PR: Wk 4 - Strategic Communications
Fundamentals of PR: Wk 4 - Strategic CommunicationsFundamentals of PR: Wk 4 - Strategic Communications
Fundamentals of PR: Wk 4 - Strategic Communications
Jordan Williams
 
Vitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd year
Vitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd yearVitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd year
Vitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd year
ARUN KUMAR
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptx
milanasargsyan5
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
Diabetic neuropathy peripheral autonomic
Diabetic neuropathy peripheral autonomicDiabetic neuropathy peripheral autonomic
Diabetic neuropathy peripheral autonomic
Pankaj Patawari
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
Timber Pitch Roof Construction Measurement-2024.pptx
Timber Pitch Roof Construction Measurement-2024.pptxTimber Pitch Roof Construction Measurement-2024.pptx
Timber Pitch Roof Construction Measurement-2024.pptx
Tantish QS, UTM
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Fundamentals of PR: Wk 4 - Strategic Communications
Fundamentals of PR: Wk 4 - Strategic CommunicationsFundamentals of PR: Wk 4 - Strategic Communications
Fundamentals of PR: Wk 4 - Strategic Communications
Jordan Williams
 
Vitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd year
Vitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd yearVitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd year
Vitamins Chapter-7, Biochemistry and clinical pathology, D.Pharm 2nd year
ARUN KUMAR
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 

JavaScript

  • 3. Submit Data From HTML Form <HTML> <HEAD></HEAD> <BODY> <FORM METHOD=“GET” ACTION="HelloName.jsp"> Enter Name <INPUT TYPE="text" NAME="fName"> <INPUT VALUE="GO" TYPE="submit"> </FORM> </BODY> </HTML> GET POST On Submit - http://localhost:8080/aajkiapp/HelloName.jsp?fName=Sunrays www.SunilOS.com 3
  • 4. FORM Fields  <FORM METHOD=GET ACTION="">  Text Field<INPUT TYPE="text" NAME="userId"><BR>  Password Field<INPUT TYPE="password" NAME ="pwd"><BR>  Checkbox Field<INPUT TYPE="checkbox" NAME="checkBox" VALUE="1" ><BR>  Radio Field<INPUT TYPE="radio" NAME="degree" VALUE="MCA">  <INPUT TYPE="radio" NAME="degree" VALUE="BE"><BR>  Button <INPUT TYPE="button" NAME="action" VALUE="Go"><BR>  Submit Button<INPUT TYPE="Submit" VALUE="Submit"><BR> www.SunilOS.com 4
  • 5. FORM Fields (Cont.)  Reset Button<INPUT TYPE="reset" VALUE="Clear"><BR>  TextArea<TEXTAREA NAME="tArea" ROWS="2" COLS="20"></TEXTAREA><BR>  List <SELECT NAME="list">  <OPTION VALUE="1">ONE</OPTION>  <OPTION VALUE="2">TWO</OPTION>  </SELECT><BR>  Hidden Value<INPUT TYPE="hidden" NAME="id" VALUE="123">  </FORM> www.SunilOS.com 5
  • 7. JavaScript It is the scripting language of the Web. It is used in millions of Web pages to add functionalities: o Validate forms o Detect browsers o Handle Cookies ..and much more www.SunilOS.com 7
  • 8. <script> Tag  <HTML>  <HEAD> o <SCRIPT LANGUAGE="JavaScript"> o function hello(){ o alert(“Pahala Pahala Click"); o } o </SCRIPT>  </HEAD>  <input name="operation" type="button" value="Click Me"  onclick="hello()" > www.SunilOS.com 8
  • 9. Key points  Javascript functions are written in script tag. o <script language="text/javascript">…</script>  Tag <script > can be written anywhere in HTML but <HEAD> tag is preferred to write it because head position is first loaded in browser.  Function is always started with 'function' key word.  Variables are defined by optional 'var' keyword. For example o var msg =0; //with var o OR o msg=0; //witout var www.SunilOS.com 9
  • 10. Key points (Cont.)  Data type of a variable is depending on its stored value. o var num= 1; //integer o var name ="sunrays“; //string o var salary = 1.5; //float  String can be represented by single quote (') or double quote (") in Javascript. o var org = “sunrays”; o var org = 'sunrays' ; www.SunilOS.com 10
  • 11. <INPUT event Attribute The event occurs when... onabort Loading of an image is interrupted onblur An element loses focus onchange The user changes the content of a field onclick Mouse clicks an object ondblclick Mouse double-clicks an object onerror An error occurs when loading a document or an image onfocus An element gets focus onkeydown A keyboard key is pressed onkeypress A keyboard key is pressed or held down onkeyup A keyboard key is released onload A page or an image is finished loading www.SunilOS.com 11
  • 12. Javascript Objects  <HTML>  <HEAD></HEAD>  <BODY>  <FORM NAME=‘helloForm’ METHOD=“GET” ACTION="HelloName.jsp"> o Enter Name o <INPUT TYPE="text" NAME=“name“ VALUE=‘XYZ’>  <INPUT VALUE="GO" TYPE="submit">  </FORM>  </BODY>  </HTML> document form name alert(document.helloForm.name.value); www.SunilOS.com 12
  • 13. Confirm Box (Are You Sure) ? <form action="Abc.jsp"> Roll NO <input type="text" name="rollNo"> <input name="operation" type="button" value="Delete“ onclick="doDelete(this.form)" > </form> www.SunilOS.com 13
  • 14. Confirm Box ( Cont.)  <script type="text/javascript">  function doDelete(frm){   if(frm.rollNo.value == ''){  alert("Roll number can not be null")  frm.rollNo.focus();  }else {  var flag = confirm("Are you sure ?");  if(flag){  frm.submit();  }  }  }  </script> www.SunilOS.com 14
  • 15. Sum of two Numbers  <form name=“calForm” >  <input type="text" name="num1">+  <input type="text" name="num2">=  <input type="text" name="sum" readonly=“true">  <input type="button" value="Calculate" onclick="calc(document.calForm)" >  <input type="button" value="Calculate“ onclick="calc(this.form)" >  </form> www.SunilOS.com 15
  • 16. Sum of two Numbers  <form action="">  <input type="text" name="num1“ onchange="calc(this.form)" >  + <input type="text" name="num2“ onchange="calc(this.form)" >  = <input type="text" name="sum" readonly=“true">  <input type="button" value="Calculate" onclick="calc(this.form)" >  </form> www.SunilOS.com 16
  • 17. Calculate Sum <script type="text/javascript"> function calc(frm){  var n1 = parseInt(frm.num1.value);  var n2 = parseInt(frm.num2.value);  frm.sum.value = n1 + n2;  return frm.sum.value; } </script> www.SunilOS.com 17
  • 18. Validation on form submit <form onsubmit="return validate(this)"> o User ID <input type="text" name="id"><br> o Password <input type=“text" name="pwd"> o <input type="submit" value=“Go" > </form> www.SunilOS.com 18
  • 19. Validate method  function validate(frm){   var flag = true;  if(frm.id.value == ''){  alert("User ID can not be null");  flag = false;  }  if(frm.pwd.value == ''){  alert("Password can not be null");  flag = false;  }  return flag;  } www.SunilOS.com 19
  • 20. Reusable functions .js file Reusable functions can be stored in a text file that has extension .js. HTML pages can import functions from a .js file to use them. HTML pages can import multiple .js files. Include .js files into HTML by <script> tag: o <script type="text/javascript" src="menu.js"> o <script type="text/javascript" src=“calendar.js"> www.SunilOS.com 20
  • 21. Javascript Frameworks JQuery Angular JS Ext JS Prototype DOJO www.SunilOS.com 21
  • 22. AJAX  Asynchronous JavaScript and XML  HTML pages call a web resource (web page) asynchronously (in the background) without impacting existing displaying page.  HTML pages can send and receive data with the help of AJAX from the source server asynchronously.  Object XMLHttpRequest is used to make asynchronous calls.  Usually JSON data fetched by AJAX calls. www.SunilOS.com 22
  • 23. Get XmlHttpObject  function getXmlHttpObject(){  var xmlHttp=null;  try{  // Firefox, Opera 8.0+, Safari  xmlHttp=new XMLHttpRequest();  }  catch (e){  // Internet Explorer  try{  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");  }  catch (e){  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");  }  }  return xmlHttp;  } www.SunilOS.com 23
  • 24. HTML  Sign Up Guest :  <INPUT TYPE="radio“ NAME="site“ onClick="getContent(‘/App/Guest')">  Sign Up Patient:  <INPUT TYPE="radio" NAME="site“ onClick="getContent('/App/Patient')">  Sign Up Doctor:  <INPUT TYPE="radio" NAME="site“ onClick="getContent('/App/Doctor')" >  <TD id='bodyText'> AJAX Text will be replaced here </TD> www.SunilOS.com 24
  • 25. Get Data  function getContent(url){ o var xmlHttp = getXmlHttpObject(); o xmlHttp.open("GET",url,true); o //attach function o xmlHttp.onreadystatechange=function(){  if(xmlHttp.readyState==4 && xmlHttp.status == 200) { • var cont = xmlHttp.responseText; • document.getElementById('bodyText').innerHTML = cont;  } o } o xmlHttp.send(null);  } www.SunilOS.com 25
  • 26. Disclaimer This is an educational presentation to enhance the skill of computer science students. This presentation is available for free to computer science students. Some internet images from different URLs are used in this presentation to simplify technical examples and correlate examples with the real world. We are grateful to owners of these URLs and pictures. www.SunilOS.com 26