SlideShare a Scribd company logo
JavaScript - Syntax
JavaScriptcan be implementedusingJavaScriptstatementsthatare placedwithinthe <script>...
</script> HTML tags in a webpage.
youcan place the <script> tags,containingyourJavaScript,anywhere withinyouwebpage,butitis
normallyrecommendedthatyoushouldkeepitwithinthe <head>tags.
Helloworldin JavaScript
<html>
<body>
<script language="javascript"type="text/javascript">
document.write("HelloWorld!")
</script>
</body>
</html>
Case Sensitivity
JavaScript is a case-sensitive language. This means that the language keywords, variables,
function names, and any other identifiers must always be typed with a consistent capitalization of
letters.
Comments in JavaScript
JavaScript supports both C-style and C++-style comments, Thus −
 Any text between a // and the end of a line is treated as a comment and is ignored by
JavaScript.
 Any text between the characters /* and */ is treated as a comment. This may span
multiple lines.
 JavaScript also recognizes the HTML comment opening sequence <!--. JavaScript treats
this as a single-line comment, just as it does the // comment.
 The HTML comment closing sequence --> is not recognized by JavaScript so it should be
written as //-->.
JavaScript Output
JavaScript can "display" data in different ways:
 Writing into an alert box, using window.alert().
 Writing into the HTML output using document.write().
 Writing into an HTML element, using innerHTML.
 Writing into the browser console, using console.log().
***Writing into an alert box, using window.alert().
<!DOCTYPE html>
<html>
<body>
<h1>My First Web Page</h1>
<p>My first paragraph.</p>
<script>
window.alert(5 + 6);
</script>
</body>
</html>
Using document.write()
<!DOCTYPE html>
<html>
<body>
<h1>My First Web Page</h1>
<p>My first paragraph.</p>
<script>
document.write(5 + 6);
</script>
</body>
</html>
Using innerHTML
<!DOCTYPE html>
<html>
<body>
<h1>My First Web Page</h1>
<p>My First Paragraph</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = 5 + 6;
</script>
</body>
</html>
What Is a Regular Expression?
A regular expression is a sequence of characters that forms a search pattern.
When you search for data in a text, you can use this search pattern to describe what you are
searching for.
A regular expression can be a single character, or a more complicated pattern.
Regular expressions can be used to perform all types of text search and text replace operations.
JavaScript Form Validation
HTML form validation can be done by a JavaScript.
If a form field (fname) is empty, this function alerts a message, and returns false, to prevent the
form from being
function validateForm() {
var x = document.forms["myForm"]["fname"].value;
if (x == null || x == "") {
alert("Name must be filledout");
return false;
}
}
<!DOCTYPE html>
<html>
<body>
<form action="demo_form.asp" method="post">
<input type="text"name="fname" required>
<input type="submit"value="Submit">
</form>
<p>If you clicksubmit, without fillingout the text field,
your browser will display an error message.</p>
</body>
</html>
Basic FormValidation
<script type="text/javascript">
<!--
// Form validation code will come here.
function validate()
{
if( document.myForm.Name.value == "" )
{
alert( "Please provide your name!" );
document.myForm.Name.focus() ;
return false;
}
if( document.myForm.EMail.value == "" )
{
alert( "Please provide your Email!" );
document.myForm.EMail.focus() ;
return false;
}
if( document.myForm.Zip.value == "" ||
isNaN( document.myForm.Zip.value ) ||
document.myForm.Zip.value.length != 5 )
{
alert( "Please provide a zip in the format #####."
);
document.myForm.Zip.focus() ;
return false;
}
if( document.myForm.Country.value == "-1" )
{
alert( "Please provide your country!" );
return false;
}
return( true );
}
//-->
</script>
Data Format Validation
<script type="text/javascript">
<!--
function validateEmail()
{
var emailID = document.myForm.EMail.value;
atpos = emailID.indexOf("@");
dotpos = emailID.lastIndexOf(".");
if (atpos < 1 || ( dotpos - atpos < 2 ))
{
alert("Please enter correct email ID")
document.myForm.EMail.focus() ;
return false;
}
return( true );
}
//-->
</script>
The checkValidity() Method
<!DOCTYPE html>
<html>
<body>
<p>Enter a number and click OK:</p>
<input id="id1" type="number" min="100" max="300">
<button onclick="myFunction()">OK</button>
<p>If the number is less than 100 or greater than 300, an error
message will be displayed.</p>
<p id="demo"></p>
<script>
function myFunction() {
var inpObj = document.getElementById("id1");
if (inpObj.checkValidity() == false) {
document.getElementById("demo").innerHTML =
inpObj.validationMessage;
} else {
document.getElementById("demo").innerHTML = "Input OK";
}
}
</script>
</body>
</html>
Changing HTML Style
<!DOCTYPE html>
<html>
<body>
<p id="p1">Hello World!</p>
<p id="p2">Hello World!</p>
<script>
document.getElementById("p2").style.color = "blue";
document.getElementById("p2").style.fontFamily = "Arial";
document.getElementById("p2").style.fontSize = "larger";
</script>
<p>The paragraph above was changed by a script.</p>
</body>
</html>
Java script

More Related Content

What's hot

1. java script language fundamentals
1. java script language fundamentals1. java script language fundamentals
1. java script language fundamentals
Rajiv Gupta
 
Java Script An Introduction By HWA
Java Script An Introduction By HWAJava Script An Introduction By HWA
Java Script An Introduction By HWA
Emma Wood
 
Java script
Java scriptJava script
Java script
ITz_1
 
Java script basics
Java script basicsJava script basics
Java script basics
Thakur Amit Tomer
 
Java script
Java scriptJava script
Java script
Soham Sengupta
 
Java script
Java scriptJava script
Java script
Jay Patel
 
Java script
Java scriptJava script
Java script
Rajkiran Mummadi
 
JavaScript with Syntax & Implementation
JavaScript with Syntax & ImplementationJavaScript with Syntax & Implementation
JavaScript with Syntax & Implementation
Soumen Santra
 
Basic JavaScript Tutorial
Basic JavaScript TutorialBasic JavaScript Tutorial
Basic JavaScript Tutorial
DHTMLExtreme
 
Javascript
JavascriptJavascript
Javascript
Nagarajan
 
Unbreakable Domain Models PHPUK 2014 London
Unbreakable Domain Models PHPUK 2014 LondonUnbreakable Domain Models PHPUK 2014 London
Unbreakable Domain Models PHPUK 2014 London
Mathias Verraes
 
Basics of Javascript
Basics of Javascript Basics of Javascript
Basics of Javascript
poojanov04
 
Active browser web page
Active browser web pageActive browser web page
Active browser web page
Zee1481
 
Complete Notes on Angular 2 and TypeScript
Complete Notes on Angular 2 and TypeScriptComplete Notes on Angular 2 and TypeScript
Complete Notes on Angular 2 and TypeScript
EPAM Systems
 
Java script Session No 1
Java script Session No 1Java script Session No 1
Java script Session No 1
Saif Ullah Dar
 
Java script
Java scriptJava script
Java script
Sanjay Gunjal
 
Java script
Java scriptJava script
Java script
Sadeek Mohammed
 
Angular js form validation with ngmessages shashi-19-7-16
Angular js form validation with ngmessages shashi-19-7-16Angular js form validation with ngmessages shashi-19-7-16
Angular js form validation with ngmessages shashi-19-7-16
Shashikant Bhongale
 
Java script
Java scriptJava script
Java script
Shyam Khant
 
Form using html and java script validation
Form using html and java script validationForm using html and java script validation
Form using html and java script validation
Maitree Patel
 

What's hot (20)

1. java script language fundamentals
1. java script language fundamentals1. java script language fundamentals
1. java script language fundamentals
 
Java Script An Introduction By HWA
Java Script An Introduction By HWAJava Script An Introduction By HWA
Java Script An Introduction By HWA
 
Java script
Java scriptJava script
Java script
 
Java script basics
Java script basicsJava script basics
Java script basics
 
Java script
Java scriptJava script
Java script
 
Java script
Java scriptJava script
Java script
 
Java script
Java scriptJava script
Java script
 
JavaScript with Syntax & Implementation
JavaScript with Syntax & ImplementationJavaScript with Syntax & Implementation
JavaScript with Syntax & Implementation
 
Basic JavaScript Tutorial
Basic JavaScript TutorialBasic JavaScript Tutorial
Basic JavaScript Tutorial
 
Javascript
JavascriptJavascript
Javascript
 
Unbreakable Domain Models PHPUK 2014 London
Unbreakable Domain Models PHPUK 2014 LondonUnbreakable Domain Models PHPUK 2014 London
Unbreakable Domain Models PHPUK 2014 London
 
Basics of Javascript
Basics of Javascript Basics of Javascript
Basics of Javascript
 
Active browser web page
Active browser web pageActive browser web page
Active browser web page
 
Complete Notes on Angular 2 and TypeScript
Complete Notes on Angular 2 and TypeScriptComplete Notes on Angular 2 and TypeScript
Complete Notes on Angular 2 and TypeScript
 
Java script Session No 1
Java script Session No 1Java script Session No 1
Java script Session No 1
 
Java script
Java scriptJava script
Java script
 
Java script
Java scriptJava script
Java script
 
Angular js form validation with ngmessages shashi-19-7-16
Angular js form validation with ngmessages shashi-19-7-16Angular js form validation with ngmessages shashi-19-7-16
Angular js form validation with ngmessages shashi-19-7-16
 
Java script
Java scriptJava script
Java script
 
Form using html and java script validation
Form using html and java script validationForm using html and java script validation
Form using html and java script validation
 

Viewers also liked

Celiaquia y piel
Celiaquia y pielCeliaquia y piel
Celiaquia y piel
Sandra Pérez M
 
Petr Nikolas Prokop - Symfony framework (0. sraz přátel Symfony v Hradci Král...
Petr Nikolas Prokop - Symfony framework (0. sraz přátel Symfony v Hradci Král...Petr Nikolas Prokop - Symfony framework (0. sraz přátel Symfony v Hradci Král...
Petr Nikolas Prokop - Symfony framework (0. sraz přátel Symfony v Hradci Král...
Péhápkaři
 
Conteo
ConteoConteo
Harold boigues a man who can persevere any challenge
Harold boigues   a  man who can persevere any challengeHarold boigues   a  man who can persevere any challenge
Harold boigues a man who can persevere any challenge
Harold Boigues
 
Garage storage solutions in fort worth tx
Garage storage solutions in fort worth txGarage storage solutions in fort worth tx
Garage storage solutions in fort worth tx
Garaginization Dfw
 
Lectura 2 qué es ser persona para el derecho
Lectura 2 qué es ser persona para el derechoLectura 2 qué es ser persona para el derecho
Lectura 2 qué es ser persona para el derecho
Godofredo Lozano
 
NMBC-INFOCOM-3RD-QUARTER-2015_WEB-VERSION
NMBC-INFOCOM-3RD-QUARTER-2015_WEB-VERSIONNMBC-INFOCOM-3RD-QUARTER-2015_WEB-VERSION
NMBC-INFOCOM-3RD-QUARTER-2015_WEB-VERSIONGary Blom
 
Catherine cowden
Catherine cowdenCatherine cowden
Catherine cowden
Catherine Cowden
 
Tomáš Strejček - Velikost týmu vs. monolith a mikroservicy (11. sraz přátel ...
Tomáš Strejček - Velikost týmu vs. monolith a mikroservicy  (11. sraz přátel ...Tomáš Strejček - Velikost týmu vs. monolith a mikroservicy  (11. sraz přátel ...
Tomáš Strejček - Velikost týmu vs. monolith a mikroservicy (11. sraz přátel ...
Péhápkaři
 
oclusión_ Protesico Dental .primer año
oclusión_ Protesico Dental .primer año oclusión_ Protesico Dental .primer año
oclusión_ Protesico Dental .primer año Mony Perez
 
Lectura 03
Lectura 03Lectura 03
Lectura 03
Rossy Camila
 
Piezas dentales
Piezas dentalesPiezas dentales
Piezas dentalesMony Perez
 
Facebook Instant Articles и Google AMP: что это и зачем онлайн-изданиям
Facebook Instant Articles и Google AMP: что это и зачем онлайн-изданиямFacebook Instant Articles и Google AMP: что это и зачем онлайн-изданиям
Facebook Instant Articles и Google AMP: что это и зачем онлайн-изданиям
Mediaprojects Mail.Ru Group
 
Boreas AHU [RU]
Boreas AHU [RU]Boreas AHU [RU]
Boreas AHU [RU]
Haluk TOSUN
 
Course Outline
Course OutlineCourse Outline
Course Outline
nutty_npk
 
Txns_iPhone_Working_Splits
Txns_iPhone_Working_SplitsTxns_iPhone_Working_Splits
Txns_iPhone_Working_SplitsLuke Eastman
 
The Largest E-Cig Company for Smok Ultra Mod
The Largest E-Cig Company for Smok Ultra ModThe Largest E-Cig Company for Smok Ultra Mod
The Largest E-Cig Company for Smok Ultra Mod
vapingman
 
Redessociales
RedessocialesRedessociales
RedessocialesRoleiva15
 
Bapenas verbal1
Bapenas verbal1Bapenas verbal1
Bapenas verbal1
sadam akbar
 

Viewers also liked (20)

Celiaquia y piel
Celiaquia y pielCeliaquia y piel
Celiaquia y piel
 
Petr Nikolas Prokop - Symfony framework (0. sraz přátel Symfony v Hradci Král...
Petr Nikolas Prokop - Symfony framework (0. sraz přátel Symfony v Hradci Král...Petr Nikolas Prokop - Symfony framework (0. sraz přátel Symfony v Hradci Král...
Petr Nikolas Prokop - Symfony framework (0. sraz přátel Symfony v Hradci Král...
 
Conteo
ConteoConteo
Conteo
 
Harold boigues a man who can persevere any challenge
Harold boigues   a  man who can persevere any challengeHarold boigues   a  man who can persevere any challenge
Harold boigues a man who can persevere any challenge
 
Garage storage solutions in fort worth tx
Garage storage solutions in fort worth txGarage storage solutions in fort worth tx
Garage storage solutions in fort worth tx
 
Lectura 2 qué es ser persona para el derecho
Lectura 2 qué es ser persona para el derechoLectura 2 qué es ser persona para el derecho
Lectura 2 qué es ser persona para el derecho
 
NMBC-INFOCOM-3RD-QUARTER-2015_WEB-VERSION
NMBC-INFOCOM-3RD-QUARTER-2015_WEB-VERSIONNMBC-INFOCOM-3RD-QUARTER-2015_WEB-VERSION
NMBC-INFOCOM-3RD-QUARTER-2015_WEB-VERSION
 
Catherine cowden
Catherine cowdenCatherine cowden
Catherine cowden
 
Tomáš Strejček - Velikost týmu vs. monolith a mikroservicy (11. sraz přátel ...
Tomáš Strejček - Velikost týmu vs. monolith a mikroservicy  (11. sraz přátel ...Tomáš Strejček - Velikost týmu vs. monolith a mikroservicy  (11. sraz přátel ...
Tomáš Strejček - Velikost týmu vs. monolith a mikroservicy (11. sraz přátel ...
 
oclusión_ Protesico Dental .primer año
oclusión_ Protesico Dental .primer año oclusión_ Protesico Dental .primer año
oclusión_ Protesico Dental .primer año
 
Lectura 03
Lectura 03Lectura 03
Lectura 03
 
Piezas dentales
Piezas dentalesPiezas dentales
Piezas dentales
 
Facebook Instant Articles и Google AMP: что это и зачем онлайн-изданиям
Facebook Instant Articles и Google AMP: что это и зачем онлайн-изданиямFacebook Instant Articles и Google AMP: что это и зачем онлайн-изданиям
Facebook Instant Articles и Google AMP: что это и зачем онлайн-изданиям
 
Boreas AHU [RU]
Boreas AHU [RU]Boreas AHU [RU]
Boreas AHU [RU]
 
Course Outline
Course OutlineCourse Outline
Course Outline
 
Txns_iPhone_Working_Splits
Txns_iPhone_Working_SplitsTxns_iPhone_Working_Splits
Txns_iPhone_Working_Splits
 
The Largest E-Cig Company for Smok Ultra Mod
The Largest E-Cig Company for Smok Ultra ModThe Largest E-Cig Company for Smok Ultra Mod
The Largest E-Cig Company for Smok Ultra Mod
 
Depre.jodo
Depre.jodoDepre.jodo
Depre.jodo
 
Redessociales
RedessocialesRedessociales
Redessociales
 
Bapenas verbal1
Bapenas verbal1Bapenas verbal1
Bapenas verbal1
 

Similar to Java script

FSJavaScript.ppt
FSJavaScript.pptFSJavaScript.ppt
FSJavaScript.ppt
AbhishekKumar66407
 
Introduction to java script
Introduction to java scriptIntroduction to java script
Introduction to java script
nanjil1984
 
JAVA SCRIPT
JAVA SCRIPTJAVA SCRIPT
JAVA SCRIPT
Mohammed Hussein
 
1472251766_demojavascriptppt (1).ppt
1472251766_demojavascriptppt (1).ppt1472251766_demojavascriptppt (1).ppt
1472251766_demojavascriptppt (1).ppt
ictlab3
 
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
 
Introduction of javascript
Introduction of javascriptIntroduction of javascript
Introduction of javascript
syeda zoya mehdi
 
Web programming
Web programmingWeb programming
Web programming
Leo Mark Villar
 
Javascript
JavascriptJavascript
Javascript
D V BHASKAR REDDY
 
Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]srikanthbkm
 
Java scripts
Java scriptsJava scripts
Java scripts
Capgemini India
 
Java scipt
Java sciptJava scipt
Javascript basics
Javascript basicsJavascript basics
Javascript basics
shreesenthil
 
Javascript sivasoft
Javascript sivasoftJavascript sivasoft
Javascript sivasoftch samaram
 
FYBSC IT Web Programming Unit III Javascript
FYBSC IT Web Programming Unit III JavascriptFYBSC IT Web Programming Unit III Javascript
FYBSC IT Web Programming Unit III Javascript
Arti Parab Academics
 
wp-UNIT_III.pptx
wp-UNIT_III.pptxwp-UNIT_III.pptx
wp-UNIT_III.pptx
GANDHAMKUMAR2
 
Javascript survival for CSBN Sophomores
Javascript survival for CSBN SophomoresJavascript survival for CSBN Sophomores
Javascript survival for CSBN Sophomores
Andy de Vera
 

Similar to Java script (20)

FSJavaScript.ppt
FSJavaScript.pptFSJavaScript.ppt
FSJavaScript.ppt
 
Introduction to java script
Introduction to java scriptIntroduction to java script
Introduction to java script
 
JAVA SCRIPT
JAVA SCRIPTJAVA SCRIPT
JAVA SCRIPT
 
1472251766_demojavascriptppt (1).ppt
1472251766_demojavascriptppt (1).ppt1472251766_demojavascriptppt (1).ppt
1472251766_demojavascriptppt (1).ppt
 
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
 
Introduction of javascript
Introduction of javascriptIntroduction of javascript
Introduction of javascript
 
Unit 2.4
Unit 2.4Unit 2.4
Unit 2.4
 
Unit 2.4
Unit 2.4Unit 2.4
Unit 2.4
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Web programming
Web programmingWeb programming
Web programming
 
Javascript
JavascriptJavascript
Javascript
 
Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]
 
Java scripts
Java scriptsJava scripts
Java scripts
 
Java scipt
Java sciptJava scipt
Java scipt
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Javascript sivasoft
Javascript sivasoftJavascript sivasoft
Javascript sivasoft
 
FYBSC IT Web Programming Unit III Javascript
FYBSC IT Web Programming Unit III JavascriptFYBSC IT Web Programming Unit III Javascript
FYBSC IT Web Programming Unit III Javascript
 
wp-UNIT_III.pptx
wp-UNIT_III.pptxwp-UNIT_III.pptx
wp-UNIT_III.pptx
 
Javascript survival for CSBN Sophomores
Javascript survival for CSBN SophomoresJavascript survival for CSBN Sophomores
Javascript survival for CSBN Sophomores
 

Recently uploaded

AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
ankuprajapati0525
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
addressing modes in computer architecture
addressing modes  in computer architectureaddressing modes  in computer architecture
addressing modes in computer architecture
ShahidSultan24
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSETECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
DuvanRamosGarzon1
 
Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
Kamal Acharya
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 

Recently uploaded (20)

AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
addressing modes in computer architecture
addressing modes  in computer architectureaddressing modes  in computer architecture
addressing modes in computer architecture
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSETECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
 
Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 

Java script

  • 1. JavaScript - Syntax JavaScriptcan be implementedusingJavaScriptstatementsthatare placedwithinthe <script>... </script> HTML tags in a webpage. youcan place the <script> tags,containingyourJavaScript,anywhere withinyouwebpage,butitis normallyrecommendedthatyoushouldkeepitwithinthe <head>tags. Helloworldin JavaScript <html> <body> <script language="javascript"type="text/javascript"> document.write("HelloWorld!") </script> </body> </html> Case Sensitivity JavaScript is a case-sensitive language. This means that the language keywords, variables, function names, and any other identifiers must always be typed with a consistent capitalization of letters. Comments in JavaScript JavaScript supports both C-style and C++-style comments, Thus −
  • 2.  Any text between a // and the end of a line is treated as a comment and is ignored by JavaScript.  Any text between the characters /* and */ is treated as a comment. This may span multiple lines.  JavaScript also recognizes the HTML comment opening sequence <!--. JavaScript treats this as a single-line comment, just as it does the // comment.  The HTML comment closing sequence --> is not recognized by JavaScript so it should be written as //-->. JavaScript Output JavaScript can "display" data in different ways:  Writing into an alert box, using window.alert().  Writing into the HTML output using document.write().  Writing into an HTML element, using innerHTML.  Writing into the browser console, using console.log(). ***Writing into an alert box, using window.alert(). <!DOCTYPE html> <html> <body> <h1>My First Web Page</h1> <p>My first paragraph.</p> <script> window.alert(5 + 6); </script> </body> </html>
  • 3. Using document.write() <!DOCTYPE html> <html> <body> <h1>My First Web Page</h1> <p>My first paragraph.</p> <script> document.write(5 + 6); </script> </body> </html> Using innerHTML <!DOCTYPE html> <html> <body> <h1>My First Web Page</h1> <p>My First Paragraph</p> <p id="demo"></p> <script> document.getElementById("demo").innerHTML = 5 + 6; </script> </body> </html>
  • 4. What Is a Regular Expression? A regular expression is a sequence of characters that forms a search pattern. When you search for data in a text, you can use this search pattern to describe what you are searching for. A regular expression can be a single character, or a more complicated pattern. Regular expressions can be used to perform all types of text search and text replace operations. JavaScript Form Validation HTML form validation can be done by a JavaScript. If a form field (fname) is empty, this function alerts a message, and returns false, to prevent the form from being function validateForm() { var x = document.forms["myForm"]["fname"].value; if (x == null || x == "") { alert("Name must be filledout"); return false; } } <!DOCTYPE html> <html> <body>
  • 5. <form action="demo_form.asp" method="post"> <input type="text"name="fname" required> <input type="submit"value="Submit"> </form> <p>If you clicksubmit, without fillingout the text field, your browser will display an error message.</p> </body> </html> Basic FormValidation <script type="text/javascript"> <!--
  • 6. // Form validation code will come here. function validate() { if( document.myForm.Name.value == "" ) { alert( "Please provide your name!" ); document.myForm.Name.focus() ; return false; } if( document.myForm.EMail.value == "" ) { alert( "Please provide your Email!" ); document.myForm.EMail.focus() ; return false; } if( document.myForm.Zip.value == "" || isNaN( document.myForm.Zip.value ) || document.myForm.Zip.value.length != 5 ) { alert( "Please provide a zip in the format #####." ); document.myForm.Zip.focus() ; return false; } if( document.myForm.Country.value == "-1" ) { alert( "Please provide your country!" ); return false; } return( true ); } //--> </script> Data Format Validation <script type="text/javascript"> <!--
  • 7. function validateEmail() { var emailID = document.myForm.EMail.value; atpos = emailID.indexOf("@"); dotpos = emailID.lastIndexOf("."); if (atpos < 1 || ( dotpos - atpos < 2 )) { alert("Please enter correct email ID") document.myForm.EMail.focus() ; return false; } return( true ); } //--> </script> The checkValidity() Method <!DOCTYPE html> <html> <body> <p>Enter a number and click OK:</p>
  • 8. <input id="id1" type="number" min="100" max="300"> <button onclick="myFunction()">OK</button> <p>If the number is less than 100 or greater than 300, an error message will be displayed.</p> <p id="demo"></p> <script> function myFunction() { var inpObj = document.getElementById("id1"); if (inpObj.checkValidity() == false) { document.getElementById("demo").innerHTML = inpObj.validationMessage; } else { document.getElementById("demo").innerHTML = "Input OK"; } } </script>
  • 9. </body> </html> Changing HTML Style <!DOCTYPE html> <html> <body> <p id="p1">Hello World!</p> <p id="p2">Hello World!</p> <script> document.getElementById("p2").style.color = "blue"; document.getElementById("p2").style.fontFamily = "Arial"; document.getElementById("p2").style.fontSize = "larger"; </script> <p>The paragraph above was changed by a script.</p> </body> </html>