SlideShare a Scribd company logo
1 of 15
Introduction to Function
1.  What are the type of HTML input elements?
2.  Identify and what type of input elements are shown below.
a.<form>
    First name: <input type="text" name="firstname" /><br />
    </form>
b. <form>
     <input type=“button" value=“Click" /><br />
    </form>
c.<form>
    Password: <input type="password" name="pwd" />
    </form>
d. <form>
    <input type="radio" name="sex" value="male" /> Male<br />
    </form>
e.   <form>
      <input type="checkbox" name="vehicle" value="Bike" /> I have
      a bike<br />
      </form>
   A function is a block of code that will be
    executed when "someone" calls it:
   Functions are the heart of JavaScript
   Functions are way of organizing and
    controlling different sequences of code which
    work together with other functions, page
    elements and input from the user.
   Functions contains a set of commands for
    specific purpose which you want to run at a
    certain time.              Reference:MediaCollege.com
   A function is written as a code block (inside curly { }
    braces), preceded by the function keyword:
    function functionName()
    {
    some code to be executed
    }
   The code inside the function will be executed when
    "someone" calls the function.
   The function can be called directly when an event
    occurs (like when a user clicks a button), and it can
    be called from "anywhere" by JavaScript code.
   JavaScript is case sensitive. The function keyword
    must be written in lowercase letters, and the function
    must be called with the same capitals as used in the
    function name.
1. function………keyword
                           2. myFunction……functionname
                           3. ()……..parenthesis (which may or
                              may not be containing a
                              value…called an arguments.
<html>                     4. { ……Curly braces or bracket
 <head>                    5. Alert(“statement”); …. the code to
 <script>                     be executed.
 function myFunction()     6. }……..Curly braces or bracket
 {
 alert("Hello World!");
 }                         NAMING A FUNCTION
 </script>
 </head>                   1. when naming a function, be
                              explicit, give names that can
 <body>                       identify what mission the function
 <button                      is carrying.
 onclick="myFunction()"    2. If the name of the function is a
 >Try it</button>             combination, you can type an
 </body>                      underscore between them.
 </html>                   3. Start the first letter of the first
                              word in lowercase and the first
                              letter of each of the other parts in
                              uppercase.
                   Event
   When you call a function, you can pass along some values
    to it, these values are called arguments or parameters.
   These arguments can be used inside the function.
   You can send as many arguments as you like, separated by
    commas (,)
     myFunction(argument1,argument2)

   Declare the argument, as variables, when you declare the
    function:
     function myFunction(var1,var2)
    {
    some code
    }
   The variables and the arguments must be in the expected
    order. The first variable is given the value of the first
    passed argument etc.
<head>
  <script>
  function myFunction(name,job)
  {
  alert("Welcome " + name + ", the " + job);
  }
  </script>
</head>
<body>
<button onclick="myFunction('Harry Potter','Wizard')">Try it</button
</body>



The function above will alert "Welcome Harry Potter, the
Wizard" when the button is clicked.
The function is flexible, you can call the function using
different arguments, and different welcome messages
will be given:
   Functions do not run automatically. When the
    page loads, each function waits quietly until it
    is told to run.
   To run a function you must call it. This means
    sending an instruction to the function telling
    it to run. There are two common ways to call
    a function: From an event handler and from
    another function.
   An event handler is a command which calls a
    function when an event happens, such as the
    user clicking a button. The command is
    written in the format onEvent, where Event is
    the name for a specific action
   It's not that hard to write a function in JavaScript.
    Here's an example of a JavaScript function.

   Write the function
   The first thing you need to do is write the
    function:

  <script>
function displayMessage(firstName) {
   alert("Hello " + firstName + ", hope you like
  JavaScript functions!")
}
</script>
   Call the function
   Once you have written your function, you can "call"
    that function from within your HTML code. Here,
    when the user clicks the button, it runs the function.
    In this case, we use the onclick event handler to call
    the function.

   <form>
First name:
<input type="input" name="yourName" />
<input
 type="button"
 onclick="displayMessage(form.yourName.value)"
 value="Display Message" />
</form>
<script>
function
   displayMessage(firstName) {
    alert("Hello " + firstName +
   ", hope you like JavaScript
   functions!")
}
</script>
<form>
First name:
<input type="input"
   name="yourName" />
<input
  type="button"

  onclick="displayMessage(form
  .yourName.value)"
 value="Display Message" />
</form>
   Writing the function:
   We started by using the function keyword. This
    tells the browser that a function is about to be
    defined
   Then we gave the function a name, so we made
    up our own name called "displayMessage". We
    specified the name of an argument ("firstName")
    that will be passed into this function.
   After the function name came a curly bracket {.
    This opens the function. There is also a closing
    bracket later, to close the function.
   In between the curly brackets we write all our
    code for the function. In this case, we use
    JavaScript's built in alert() function to pop up a
    message for the user.
   Calling the function:
   We created an HTML form with an input field
    and submit button
   We assigned a name ("yourName") to the
    input field
   We added the onclick event handler to the
    button. This event handler is called when the
    user clicks on the button (more about event
    handlers later). This is where we call our
    JavaScript function from. We pass it the value
    from the form's input field. We can reference
    this value by using "form.yourName.value".
Write the JavaScript source code using function
 and switch statements.



Favorite movie         Statement

case 1 = Titanic        Not a bad choice
case 2= Water World     No comment
case 3= Scream 2       It has its moments
default statement      I’m sure it was great

More Related Content

What's hot

Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...ssuserd6b1fd
 
JavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UXJavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UXJWORKS powered by Ordina
 
Lab#1 - Front End Development
Lab#1 - Front End DevelopmentLab#1 - Front End Development
Lab#1 - Front End DevelopmentWalid Ashraf
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypesVarun C M
 
MVC Design Pattern in JavaScript by ADMEC Multimedia Institute
MVC Design Pattern in JavaScript by ADMEC Multimedia InstituteMVC Design Pattern in JavaScript by ADMEC Multimedia Institute
MVC Design Pattern in JavaScript by ADMEC Multimedia InstituteRavi Bhadauria
 
Unison Language - Contact
Unison Language - ContactUnison Language - Contact
Unison Language - ContactPhilip Schwarz
 
Html basics 11 form validation
Html basics 11 form validationHtml basics 11 form validation
Html basics 11 form validationH K
 
Java Script Language Tutorial
Java Script Language TutorialJava Script Language Tutorial
Java Script Language Tutorialvikram singh
 
Java Script Promise
Java Script PromiseJava Script Promise
Java Script PromiseAlok Guha
 
Javascript conditional statements
Javascript conditional statementsJavascript conditional statements
Javascript conditional statementsnobel mujuji
 
JavaScript Best Pratices
JavaScript Best PraticesJavaScript Best Pratices
JavaScript Best PraticesChengHui Weng
 
Protocol-Oriented MVVM (extended edition)
Protocol-Oriented MVVM (extended edition)Protocol-Oriented MVVM (extended edition)
Protocol-Oriented MVVM (extended edition)Natasha Murashev
 
Javascript part1
Javascript part1Javascript part1
Javascript part1Raghu nath
 

What's hot (20)

Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
 
Books
BooksBooks
Books
 
JavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UXJavaScript Basics and Best Practices - CC FE & UX
JavaScript Basics and Best Practices - CC FE & UX
 
Lab#1 - Front End Development
Lab#1 - Front End DevelopmentLab#1 - Front End Development
Lab#1 - Front End Development
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
 
MVC Design Pattern in JavaScript by ADMEC Multimedia Institute
MVC Design Pattern in JavaScript by ADMEC Multimedia InstituteMVC Design Pattern in JavaScript by ADMEC Multimedia Institute
MVC Design Pattern in JavaScript by ADMEC Multimedia Institute
 
Unison Language - Contact
Unison Language - ContactUnison Language - Contact
Unison Language - Contact
 
Javascript essentials
Javascript essentialsJavascript essentials
Javascript essentials
 
ExtJs Basic Part-1
ExtJs Basic Part-1ExtJs Basic Part-1
ExtJs Basic Part-1
 
Html basics 11 form validation
Html basics 11 form validationHtml basics 11 form validation
Html basics 11 form validation
 
AutoComplete
AutoCompleteAutoComplete
AutoComplete
 
Protocol-Oriented MVVM
Protocol-Oriented MVVMProtocol-Oriented MVVM
Protocol-Oriented MVVM
 
Java Script Language Tutorial
Java Script Language TutorialJava Script Language Tutorial
Java Script Language Tutorial
 
Java Script Promise
Java Script PromiseJava Script Promise
Java Script Promise
 
Javascript conditional statements
Javascript conditional statementsJavascript conditional statements
Javascript conditional statements
 
Jquery 1
Jquery 1Jquery 1
Jquery 1
 
Clean code slide
Clean code slideClean code slide
Clean code slide
 
JavaScript Best Pratices
JavaScript Best PraticesJavaScript Best Pratices
JavaScript Best Pratices
 
Protocol-Oriented MVVM (extended edition)
Protocol-Oriented MVVM (extended edition)Protocol-Oriented MVVM (extended edition)
Protocol-Oriented MVVM (extended edition)
 
Javascript part1
Javascript part1Javascript part1
Javascript part1
 

Viewers also liked

Css color and background properties
Css color and background propertiesCss color and background properties
Css color and background propertiesJesus Obenita Jr.
 
Html web designing linking pages
Html web designing linking pagesHtml web designing linking pages
Html web designing linking pagesJesus Obenita Jr.
 
Form validation client side
Form validation client side Form validation client side
Form validation client side Mudasir Syed
 
Javascript validation karan chanana
Javascript validation karan chananaJavascript validation karan chanana
Javascript validation karan chananakaranchanan
 
Form Validation in JavaScript
Form Validation in JavaScriptForm Validation in JavaScript
Form Validation in JavaScriptRavi Bhadauria
 

Viewers also liked (8)

Css color and background properties
Css color and background propertiesCss color and background properties
Css color and background properties
 
Html web designing linking pages
Html web designing linking pagesHtml web designing linking pages
Html web designing linking pages
 
Chapter iv computer virus
Chapter iv  computer virusChapter iv  computer virus
Chapter iv computer virus
 
Form validation client side
Form validation client side Form validation client side
Form validation client side
 
Javascript validation karan chanana
Javascript validation karan chananaJavascript validation karan chanana
Javascript validation karan chanana
 
Javascript validating form
Javascript validating formJavascript validating form
Javascript validating form
 
Form Validation
Form ValidationForm Validation
Form Validation
 
Form Validation in JavaScript
Form Validation in JavaScriptForm Validation in JavaScript
Form Validation in JavaScript
 

Similar to Java scriptfunction

Similar to Java scriptfunction (20)

Wt unit 5
Wt unit 5Wt unit 5
Wt unit 5
 
JavaScript for real men
JavaScript for real menJavaScript for real men
JavaScript for real men
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to Javascript
 
Java script frame window
Java script frame windowJava script frame window
Java script frame window
 
[2015/2016] JavaScript
[2015/2016] JavaScript[2015/2016] JavaScript
[2015/2016] JavaScript
 
JS basics
JS basicsJS basics
JS basics
 
Javascript
JavascriptJavascript
Javascript
 
JavaScript-L20.pptx
JavaScript-L20.pptxJavaScript-L20.pptx
JavaScript-L20.pptx
 
Basics of Java Script (JS)
Basics of Java Script (JS)Basics of Java Script (JS)
Basics of Java Script (JS)
 
Function calling in js
Function calling in jsFunction calling in js
Function calling in js
 
1669958779195.pdf
1669958779195.pdf1669958779195.pdf
1669958779195.pdf
 
Java Script
Java ScriptJava Script
Java Script
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
 
Junit in mule demo
Junit in mule demoJunit in mule demo
Junit in mule demo
 
Javascript quiz. Questions to ask when recruiting developers.
Javascript quiz. Questions to ask when recruiting developers.Javascript quiz. Questions to ask when recruiting developers.
Javascript quiz. Questions to ask when recruiting developers.
 
Javascript Frameworks for Joomla
Javascript Frameworks for JoomlaJavascript Frameworks for Joomla
Javascript Frameworks for Joomla
 
JavaScript Functions
JavaScript FunctionsJavaScript Functions
JavaScript Functions
 
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STMConcurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
 
Java script
Java scriptJava script
Java script
 
[ITP - Lecture 12] Functions in C/C++
[ITP - Lecture 12] Functions in C/C++[ITP - Lecture 12] Functions in C/C++
[ITP - Lecture 12] Functions in C/C++
 

More from Jesus Obenita Jr.

More from Jesus Obenita Jr. (20)

Organization and management 3 a Evolution of Management Theory
Organization and management 3 a Evolution of Management TheoryOrganization and management 3 a Evolution of Management Theory
Organization and management 3 a Evolution of Management Theory
 
Organization and management 2 Management Function
Organization and management 2 Management FunctionOrganization and management 2 Management Function
Organization and management 2 Management Function
 
Organization and management 1
Organization and management 1Organization and management 1
Organization and management 1
 
Designing web page marquee and img tag
Designing web page  marquee and img tagDesigning web page  marquee and img tag
Designing web page marquee and img tag
 
Ms excel 2013 formatting worksheets
Ms excel 2013 formatting worksheetsMs excel 2013 formatting worksheets
Ms excel 2013 formatting worksheets
 
Ms excel 2013 data management
Ms excel 2013 data managementMs excel 2013 data management
Ms excel 2013 data management
 
Microsoft Excel introduction
Microsoft Excel introductionMicrosoft Excel introduction
Microsoft Excel introduction
 
Word 2013 working with pictures
Word 2013 working with picturesWord 2013 working with pictures
Word 2013 working with pictures
 
Word 2013 Formatting Page
Word 2013 Formatting PageWord 2013 Formatting Page
Word 2013 Formatting Page
 
Word 2013 8
Word 2013 8Word 2013 8
Word 2013 8
 
Ms word 2013 7
Ms word 2013 7Ms word 2013 7
Ms word 2013 7
 
Ms word 2013 6
Ms word 2013 6Ms word 2013 6
Ms word 2013 6
 
Ms word 2013 4
Ms word 2013 4Ms word 2013 4
Ms word 2013 4
 
Ms word 2013 2
Ms word 2013 2Ms word 2013 2
Ms word 2013 2
 
Ms word 2013
Ms word 2013Ms word 2013
Ms word 2013
 
Parts of the ms word 2013 screen and
Parts of the ms word 2013 screen andParts of the ms word 2013 screen and
Parts of the ms word 2013 screen and
 
Word processor
Word processorWord processor
Word processor
 
Session 2 test construction.mt's
Session 2   test construction.mt'sSession 2   test construction.mt's
Session 2 test construction.mt's
 
Cooking ingredients
Cooking ingredientsCooking ingredients
Cooking ingredients
 
Color theory
Color theoryColor theory
Color theory
 

Recently uploaded

Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayMakMakNepo
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxsqpmdrvczh
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 

Recently uploaded (20)

Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up Friday
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptx
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 

Java scriptfunction

  • 2. 1. What are the type of HTML input elements? 2. Identify and what type of input elements are shown below. a.<form> First name: <input type="text" name="firstname" /><br /> </form> b. <form> <input type=“button" value=“Click" /><br /> </form> c.<form> Password: <input type="password" name="pwd" /> </form> d. <form> <input type="radio" name="sex" value="male" /> Male<br /> </form> e. <form> <input type="checkbox" name="vehicle" value="Bike" /> I have a bike<br /> </form>
  • 3. A function is a block of code that will be executed when "someone" calls it:  Functions are the heart of JavaScript  Functions are way of organizing and controlling different sequences of code which work together with other functions, page elements and input from the user.  Functions contains a set of commands for specific purpose which you want to run at a certain time. Reference:MediaCollege.com
  • 4. A function is written as a code block (inside curly { } braces), preceded by the function keyword: function functionName() { some code to be executed }  The code inside the function will be executed when "someone" calls the function.  The function can be called directly when an event occurs (like when a user clicks a button), and it can be called from "anywhere" by JavaScript code.  JavaScript is case sensitive. The function keyword must be written in lowercase letters, and the function must be called with the same capitals as used in the function name.
  • 5. 1. function………keyword 2. myFunction……functionname 3. ()……..parenthesis (which may or may not be containing a value…called an arguments. <html> 4. { ……Curly braces or bracket <head> 5. Alert(“statement”); …. the code to <script> be executed. function myFunction() 6. }……..Curly braces or bracket { alert("Hello World!"); } NAMING A FUNCTION </script> </head> 1. when naming a function, be explicit, give names that can <body> identify what mission the function <button is carrying. onclick="myFunction()" 2. If the name of the function is a >Try it</button> combination, you can type an </body> underscore between them. </html> 3. Start the first letter of the first word in lowercase and the first letter of each of the other parts in uppercase. Event
  • 6. When you call a function, you can pass along some values to it, these values are called arguments or parameters.  These arguments can be used inside the function.  You can send as many arguments as you like, separated by commas (,) myFunction(argument1,argument2)  Declare the argument, as variables, when you declare the function: function myFunction(var1,var2) { some code }  The variables and the arguments must be in the expected order. The first variable is given the value of the first passed argument etc.
  • 7. <head> <script> function myFunction(name,job) { alert("Welcome " + name + ", the " + job); } </script> </head> <body> <button onclick="myFunction('Harry Potter','Wizard')">Try it</button </body> The function above will alert "Welcome Harry Potter, the Wizard" when the button is clicked. The function is flexible, you can call the function using different arguments, and different welcome messages will be given:
  • 8. Functions do not run automatically. When the page loads, each function waits quietly until it is told to run.  To run a function you must call it. This means sending an instruction to the function telling it to run. There are two common ways to call a function: From an event handler and from another function.
  • 9. An event handler is a command which calls a function when an event happens, such as the user clicking a button. The command is written in the format onEvent, where Event is the name for a specific action
  • 10. It's not that hard to write a function in JavaScript. Here's an example of a JavaScript function.  Write the function  The first thing you need to do is write the function: <script> function displayMessage(firstName) { alert("Hello " + firstName + ", hope you like JavaScript functions!") } </script>
  • 11. Call the function  Once you have written your function, you can "call" that function from within your HTML code. Here, when the user clicks the button, it runs the function. In this case, we use the onclick event handler to call the function. <form> First name: <input type="input" name="yourName" /> <input type="button" onclick="displayMessage(form.yourName.value)" value="Display Message" /> </form>
  • 12. <script> function displayMessage(firstName) { alert("Hello " + firstName + ", hope you like JavaScript functions!") } </script> <form> First name: <input type="input" name="yourName" /> <input type="button" onclick="displayMessage(form .yourName.value)" value="Display Message" /> </form>
  • 13. Writing the function:  We started by using the function keyword. This tells the browser that a function is about to be defined  Then we gave the function a name, so we made up our own name called "displayMessage". We specified the name of an argument ("firstName") that will be passed into this function.  After the function name came a curly bracket {. This opens the function. There is also a closing bracket later, to close the function.  In between the curly brackets we write all our code for the function. In this case, we use JavaScript's built in alert() function to pop up a message for the user.
  • 14. Calling the function:  We created an HTML form with an input field and submit button  We assigned a name ("yourName") to the input field  We added the onclick event handler to the button. This event handler is called when the user clicks on the button (more about event handlers later). This is where we call our JavaScript function from. We pass it the value from the form's input field. We can reference this value by using "form.yourName.value".
  • 15. Write the JavaScript source code using function and switch statements. Favorite movie Statement case 1 = Titanic Not a bad choice case 2= Water World No comment case 3= Scream 2 It has its moments default statement I’m sure it was great