BY: SITI NURBAYA ISMAIL FACULTY of COMPUTER and MATHEMATICAL SCIENCES

Slides:



Advertisements
Similar presentations
Computer Science 103 Chapter 3 Introduction to JavaScript.
Advertisements

HTML Comprehensive Concepts and Techniques Second Edition Project 8 Integrating JavaScript with HTML.
Capturing user input: Using HTML FORMs CS4320 got here on 27/11/2003.
Information Technology Center Hany Abdelwahab Computer Specialist.
Web Development & Design Foundations with XHTML Chapter 14 Key Concepts.
Introduction to JavaScript for Python Programmers
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
WEB DESIGN AND PROGRAMMING Introduction to Javascript.
CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT BY: MUHD EIZAN SHAFIQ BIN ABD AZIZ FACULTY of COMPUTER and MATHEMATICAL SCIENCES.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT
CSC318 – WEB APPLICATION DEVELOPMENT BY: MUHD EIZAN SHAFIQ BIN ABD AZIZ FACULTY of COMPUTER and MATHEMATICAL SCIENCES.
JavaScript Part 1.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 14 Key Concepts 1 Copyright © Terry Felke-Morris.
1 CSC160 Chapter 9: The Document Object. Outline Document objects Properties of the document object linkColor alinkColor vlinkColor bgColor fgColor lastModified.
CC1003N Week 6 More CSS and Javascript.. Objectives: ● More CSS Examples ● Javascript – introduction ● Uses of Javascript ● Variables ● Comments ● Control.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT BY: MUHD EIZAN SHAFIQ BIN ABD AZIZ FACULTY of COMPUTER and MATHEMATICAL SCIENCES.
JavaScript, jQuery, and Mashups Incorporating JavaScript, jQuery, and other Mashups into existing pages.
Document Objects Forms, Images and Links. The document object model Each element of an HTML document, such as an image, form, link, or button, can be.
1 CSC317/318 INTERNET PROGRAMING / DYNAMIC WEB APPLICATION DEVELOPMENT Siti Nurbaya Ismail Faculty of Computer & Mathematical Sciences, Universiti Teknologi.
Variety of JavaScript Examples Please use speaker notes for additional information!
JavaScript - Basic Concepts Prepared and Presented by Hienvinh Nguyen, Afshin Tiraie.
Sahar Mosleh California State University San MarcosPage 1 JavaScript Basic.
CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT BY: SITI NURBAYA ISMAIL FACULTY of COMPUTER and MATHEMATICAL SCIENCES.
Fluency with Information Technology INFO100 and CSE100 Katherine Deibel Katherine Deibel, Fluency in Information Technology1.
JavaScript, Fourth Edition
CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT BY: SITI NURBAYA ISMAIL FACULTY of COMPUTER and MATHEMATICAL SCIENCES.
1 Chapter 3 – JavaScript Outline Introduction Flowcharts Control Structures if Selection Structure if/else Selection Structure while Repetition Structure.
CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT BY: SITI NURBAYA ISMAIL FACULTY of COMPUTER and MATHEMATICAL SCIENCES.
Scripting with Client-Side Processing Scripting with Client Side Processing Lesson – Web Technologies Copyright © Texas Education Agency, All rights.
CPSC 233 Tutorial 5 February 2 th /3 th, Java Loop Statements A portion of a program that repeats a statement or a group of statements is called.
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
INTERNET APPLICATIONS CPIT405 JavaScript Instructor: Rasha AlOmari
WEB SYSTEMS & TECHNOLOGY. Java Script  JavaScript created by Netscape  It is also client side programming  It can be use for client side checks.
JavaScript, Sixth Edition
Build in Objects In JavaScript, almost "everything" is an object.
CHAPTER 10 JAVA SCRIPT.
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Web Systems & Technologies
Chapter 6 JavaScript: Introduction to Scripting
Web Development & Design Foundations with HTML5
HTML & teh internets.
JavaScript is a programming language designed for Web pages.
EXCEPTION HANDLING IN SERVER CLIENT PROGRAMMING
Project 9 Creating Pop-up Windows, Adding Scrolling Messages, and Validating Forms.
JavaScript Loops.
Web Development & Design Foundations with HTML5 7th Edition
WEB APPLICATION PROGRAMMING
Chapter 6: Conditional Statements and Loops
BY: SITI NURBAYA ISMAIL FACULTY of COMPUTER and MATHEMATICAL SCIENCES
CHAPTER 4 CLIENT SIDE SCRIPTING PART 2 OF 3
14 A Brief Look at JavaScript and jQuery.
Control Structure Senior Lecturer
Exercises on JavaScript & Revision
BY: SITI NURBAYA ISMAIL FACULTY of COMPUTER and MATHEMATICAL SCIENCES
Integrating JavaScript and HTML
Introduction to JavaScript for Python Programmers
T. Jumana Abu Shmais – AOU - Riyadh
Iteration: Beyond the Basic PERFORM
CS105 Introduction to Computer Concepts
BY: SITI NURBAYA ISMAIL FACULTY of COMPUTER and MATHEMATICAL SCIENCES
Conditional Statements & Loops in JavaScript
CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT
M150: Data, Computing and Information
JavaScript Basics What is JavaScript?
Introduction to Programming and JavaScript
Web Programming– UFCFB Lecture 13
CS105 Introduction to Computer Concepts JavaScript
Presentation transcript:

BY: SITI NURBAYA ISMAIL FACULTY of COMPUTER and MATHEMATICAL SCIENCES CSC317 – INTERNET PROGRAMMING CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT BY: SITI NURBAYA ISMAIL FACULTY of COMPUTER and MATHEMATICAL SCIENCES

Outline Basic JavaScript For Loop While Loop Do While Loop User-defined Function Error Checking Working with Web Pages Properties Page 2

Basic JavaScript for Loop Execute the same block of code according specified times for(var = startValue; var <= endValue; var = var + increment){ // execute the block code until var = endValue } var x; for(x = 0; x <= 10; x++){ document.write(“Number: ” + x + “<br>”); } Page 3

Basic JavaScript for Loop Another example on for loop var x; var msg = “I promise I won’t be disturb people again.”; for(x = 1; x <= 1000; x++){ document.write(msg + “<br>”); } Page 4

Basic JavaScript while Loop Execute the same block of code while a specific condition is true while(var <= endValue){ // execute the code } var x = 0; while(x <= 10){ document.write(“Number: ” + x + “<br>”); x++; // x = x + 1 } Page 5

Basic JavaScript while Loop Another example on while loop var month_name, month = 1; while(month <= 3){ if(month == 1){ month_name = “January”; } else if(month == 2){ month_name = “February”; else if(month == 3){ month_name = “March”; else{ alert(“Please select month!”); month = month + 1; Page 6

Basic JavaScript do...while Loop Execute the block of code at least once even the condition is false, because the code will be executed first before condition is tested. It will repeat the loop as long as the specified condition is true. do{ // execute the code } while(var <= endValue) var x = 0; do{ document.write(“Number is: ” + x + “<br>”); x = x + 1; } while(x < 0) Page 7

Basic JavaScript Question 1: for Loop Write a JavaScript code that will generate similar output in Figure 1. Please use for loop. Figure 1 Page 8

Basic JavaScript Question 2: for Loop Write a JavaScript code that will generate similar output in Figure 2. Please use for loop. *calculate the value within your loop Figure 2 Page 9

Basic JavaScript User-defined Function A function created by user to perform specific task <html> <head> <script type="text/javascript"> function myFunction(){ var msg = "Hello World!"; return (msg); } </script> </head> <body> document.write(myFunction()); </body> </html> Page 10

Basic JavaScript User-defined Function function xx(){ } <script language="javascript“> function kira(){ var num1=parseFloat(document.f1.num1.value); var num2=parseFloat(document.f1.num2.value); var operator=document.f1.operator.value; var sum; if(operator=="add"){ sum=num1+num2; } else if(operator=="minus"){ sum=num1-num2; else if(operator=="multiple"){ sum=num1*num2; else if(operator=="division"){ sum=num1/num2; else{ alert("select an operator"); document.f1.result.value=sum; </script> Basic JavaScript User-defined Function function xx(){ } Page 11

Basic JavaScript User-defined Function return Statement Example The return statement is used to specify the value that is returned from the function. So, functions that are going to return a value must use the return statement. The example below returns the product of two numbers (a and b): Example <html> <head> <script type="text/javascript"> function product(a,b){ return a*b; } </script> </head> <body> <script type="text/javascript"> document.write(product(4,3)); </script> </body> </html> Page 12

Basic JavaScript Error Checking Remember this example? <html> <head> <script type="text/javascript"> function myFunction(){ var fname = document.form1.fname.value; alert("Name: " + fname); } </script> </head> <body> <form name="form1"> Name: <input type="text" name="fname"> <input type=“button" name="submit" value="Submit" onclick="myFunction()"> </form> </body> </html> Page 13

Basic JavaScript Error Checking myFunction() will capture a value from fname text field. This field is specifically for people´s name, which is string value What will happen if user enter numeric value? Should myFunction() accept the value without need to do error checking? What will happen if user does not enter any value? The field leave blank. <script type="text/javascript"> function myFunction(){ var fname = document.form1.fname.value; alert("Name: " + fname); } </script> Page 14

Basic JavaScript Error Checking <script type="text/javascript"> function myFunction(){ var fname = document.form1.fname.value; if(fname == ""){ // check if no value being entered alert("Please enter a name!"); } else if(fname == null){ // check if there is undefined value else if(!isNaN(fname)){ // check if value is numeric alert("Invalid character. Name must be alphabet."); else{ // all conditions above false document.write("Name: " + fname); </script> Page 15

Basic JavaScript Error Checking fname = ″″ and fname = null are two different statements fname = ″″ : check if the value is empty fname = null : check if the value is null (undefined or unknown) Page 16

Basic JavaScript Question 3: for Loop Write a JavaScript code that will generate similar output in Figure 3. Within your form A text field for user input A button to trigger a function to check the input as numeric input to generate times calculation based on the input the calculation will start from 1 until 12. output a list of the times calculation (you can used two for loop in your coding) A button to reset the value Page 17

Basic JavaScript Question 3: for Loop Figure 3 Page 18

Basic JavaScript Question 4: for Loop Write a JavaScript code that will generate similar output in Figure 4. Within your form A text field for user input set maximum length of user input as 2 value A button to trigger a function to check the input as numeric input to check the input either odd or even output a list of different odd and even number . (you can used two for loop in your coding) A button to reset the value Page 19

Basic JavaScript Question 4: for Loop Figure 4 Page 20

Basic JavaScript Question 5: for Loop & if Statement Create a Web page embedded with JavaScript code that accepts an integer in a textbox. After the user clicks on the button, it then displays the output, which is sum of the even digits from 1 to the positive integer inserted. The output will be in an alert box. Use if statement to determine the even numbers. Then use for loop technique in order to calculate the sum of the even numbers. A sample output is shown below: Figure 5

Basic JavaScript Question 6: for Loop & if Statement Create a Web page embedded with Javascript code that accepts a positive integer in a textbox. After the user clicks on the button, it then displays the output as a series of six numbers in a textarea. Use for loop in order to calculate the value of the series. A sample output is shown below: Figure 6

Basic JavaScript Working with Web Pages Properties May be you are not realized that you have used Web Pages properties (or Document properties) a few times Example: document.write(): to display information on the web page We have others like: document.bgColor document.fgColor document.lastModified Page 24

Basic JavaScript Working with Web Pages Properties document.bgColor

Basic JavaScript Working with Web Pages Properties document.bgColor <html> <head> <script language="JavaScript"> function changeBG(color){ document.bgColor=color; //Change background color document.f1.color.value=color; //Display the color } </script> </head> <body> <form name="f1"> <input type="button" value="OceanBlue" name="Yellow" onClick="changeBG('#94FFFF')"> <input type="button" value="LimeGreen" name="Green" onClick="changeBG('#B8FF94')"> <input type="text" name="color"> </form> </body> </html> Page 26

Basic JavaScript Working with Web Pages Properties document.fgColor <html> <head> <title>document.fgcolor</title> </head> <body bgcolor="beige" text= "red" link= "green" vlink="honeydew"> <script language="javascript"> document.write("the text color is "+document.fgColor+"<br>"); </script> </body> </html> Page 27

Basic JavaScript Working with Web Pages Properties document.lastModified <html> <head> <title>document.lastModified</title> </head> <body> This document was last modified on: <script type="text/javascript"> document.write(document.lastModified); </script> </body> </html> Page 28

Bibliography (Website) Bibliography (Book) Knuckles (2001). Introduction to Interactive Programming on the Internet using HTML & Javascript. John Wiley & Sons, Inc. http://www.w3schools.com/js/default.asp Bibliography (Website) Page 29 29