SlideShare a Scribd company logo
1 of 27
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

More Related Content

What's hot

Collection v3
Collection v3Collection v3
Collection v3Sunil OS
 
JAVA Variables and Operators
JAVA Variables and OperatorsJAVA Variables and Operators
JAVA Variables and OperatorsSunil OS
 
Java Basics V3
Java Basics V3Java Basics V3
Java Basics V3Sunil OS
 
Java Threads and Concurrency
Java Threads and ConcurrencyJava Threads and Concurrency
Java Threads and ConcurrencySunil OS
 
Python part2 v1
Python part2 v1Python part2 v1
Python part2 v1Sunil OS
 
Java IO Streams V4
Java IO Streams V4Java IO Streams V4
Java IO Streams V4Sunil OS
 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File HandlingSunil OS
 
Java Networking
Java NetworkingJava Networking
Java NetworkingSunil OS
 
Resource Bundle
Resource BundleResource Bundle
Resource BundleSunil OS
 
Python Part 1
Python Part 1Python Part 1
Python Part 1Sunil OS
 
Spring Data JPA from 0-100 in 60 minutes
Spring Data JPA from 0-100 in 60 minutesSpring Data JPA from 0-100 in 60 minutes
Spring Data JPA from 0-100 in 60 minutesVMware Tanzu
 
Java Basics
Java BasicsJava Basics
Java BasicsSunil OS
 

What's hot (20)

C++
C++C++
C++
 
JUnit 4
JUnit 4JUnit 4
JUnit 4
 
Collection v3
Collection v3Collection v3
Collection v3
 
JAVA Variables and Operators
JAVA Variables and OperatorsJAVA Variables and Operators
JAVA Variables and Operators
 
JAVA OOP
JAVA OOPJAVA OOP
JAVA OOP
 
Java Basics V3
Java Basics V3Java Basics V3
Java Basics V3
 
Java Threads and Concurrency
Java Threads and ConcurrencyJava Threads and Concurrency
Java Threads and Concurrency
 
DJango
DJangoDJango
DJango
 
OOP V3.1
OOP V3.1OOP V3.1
OOP V3.1
 
PDBC
PDBCPDBC
PDBC
 
Python part2 v1
Python part2 v1Python part2 v1
Python part2 v1
 
Java IO Streams V4
Java IO Streams V4Java IO Streams V4
Java IO Streams V4
 
JDBC – Java Database Connectivity
JDBC – Java Database ConnectivityJDBC – Java Database Connectivity
JDBC – Java Database Connectivity
 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File Handling
 
Java Networking
Java NetworkingJava Networking
Java Networking
 
Resource Bundle
Resource BundleResource Bundle
Resource Bundle
 
Python Part 1
Python Part 1Python Part 1
Python Part 1
 
Spring Data JPA from 0-100 in 60 minutes
Spring Data JPA from 0-100 in 60 minutesSpring Data JPA from 0-100 in 60 minutes
Spring Data JPA from 0-100 in 60 minutes
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Javascript essentials
Javascript essentialsJavascript essentials
Javascript essentials
 

Viewers also liked

C# Variables and Operators
C# Variables and OperatorsC# Variables and Operators
C# Variables and OperatorsSunil OS
 
Javascript - Numbers
Javascript   - NumbersJavascript   - Numbers
Javascript - NumbersSamuel Santos
 
Rays Technologies
Rays TechnologiesRays Technologies
Rays TechnologiesSunil OS
 
Java Swing JFC
Java Swing JFCJava Swing JFC
Java Swing JFCSunil 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 SoftwareMayank Jain
 

Viewers also liked (10)

C# Variables and Operators
C# Variables and OperatorsC# Variables and Operators
C# Variables and Operators
 
CSS
CSS CSS
CSS
 
Javascript - Numbers
Javascript   - NumbersJavascript   - Numbers
Javascript - Numbers
 
Java script basic
Java script basicJava script basic
Java script basic
 
Rays Technologies
Rays TechnologiesRays Technologies
Rays Technologies
 
C# Basics
C# BasicsC# Basics
C# Basics
 
C++ oop
C++ oopC++ oop
C++ oop
 
Java Swing JFC
Java Swing JFCJava Swing JFC
Java Swing JFC
 
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
 
C Basics
C BasicsC Basics
C Basics
 

Similar to JavaScript

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 + Ajaxbaygross
 
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 .NETJames Johnson
 
HTML5 New and Improved
HTML5   New and ImprovedHTML5   New and Improved
HTML5 New and ImprovedTimothy 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/4DEVCON
 
HTML5 - The 2012 of the Web
HTML5 - The 2012 of the WebHTML5 - The 2012 of the Web
HTML5 - The 2012 of the WebRobert 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 MAXRobert Nyman
 
Java script Advance
Java script   AdvanceJava script   Advance
Java script AdvanceJaya 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 MVCpootsbook
 
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" DominoRob Bontekoe
 
jQuery Fundamentals
jQuery FundamentalsjQuery Fundamentals
jQuery FundamentalsGil Fink
 
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 .NETJames Johnson
 

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...
 
Introduction to Html5
Introduction to Html5Introduction to Html5
Introduction to Html5
 
Week 4 - jQuery + Ajax
Week 4 - jQuery + AjaxWeek 4 - jQuery + Ajax
Week 4 - jQuery + Ajax
 
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
 
Javascript 2
Javascript 2Javascript 2
Javascript 2
 
J query training
J query trainingJ query training
J query training
 
HTML5 New and Improved
HTML5   New and ImprovedHTML5   New and Improved
HTML5 New and Improved
 
lect4
lect4lect4
lect4
 
lect4
lect4lect4
lect4
 
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
 
HTML5 - The 2012 of the Web
HTML5 - The 2012 of the WebHTML5 - The 2012 of the Web
HTML5 - The 2012 of the Web
 
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
 
JSP
JSPJSP
JSP
 
Java script Advance
Java script   AdvanceJava script   Advance
Java script Advance
 
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
 
Practica n° 7
Practica n° 7Practica n° 7
Practica n° 7
 
Client Web
Client WebClient Web
Client Web
 
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
 
jQuery Fundamentals
jQuery FundamentalsjQuery Fundamentals
jQuery Fundamentals
 
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
 

More from Sunil OS

Threads v3
Threads v3Threads v3
Threads v3Sunil OS
 
Exception Handling v3
Exception Handling v3Exception Handling v3
Exception Handling v3Sunil 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 PandasSunil OS
 
Angular 8
Angular 8 Angular 8
Angular 8 Sunil OS
 

More from Sunil OS (8)

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

Recently uploaded

How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 

Recently uploaded (20)

Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 

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