Web Programming and Design

Slides:



Advertisements
Similar presentations
Javascript Introduction Norman White Material is from w3schools.com Go there to run examples interactively.
Advertisements

The Web Warrior Guide to Web Design Technologies
Information Technology Center Hany Abdelwahab Computer Specialist.
Computer Science 103 Chapter 4 Advanced JavaScript.
JavaScript 101 Lesson 5: Introduction to Events. Lesson Topics Event driven programming Events and event handlers The onClick event handler for hyperlinks.
Introduction to JavaScript for Python Programmers
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
Bridges To Computing General Information: This document was created for use in the "Bridges to Computing" project of Brooklyn College. You are invited.
SYST Web Technologies SYST Web Technologies Lesson 6 – Intro to JavaScript.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
CSS Class 7 Add JavaScript to your page Add event handlers Validate a form Open a new window Hide and show elements Swap images Debug JavaScript.
Week 9 PHP Cookies and Session Introduction to JavaScript.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
What is Java Script? An extension to HTML. An extension to HTML. Allows authors to incorporate some functionality in their web pages. (without using CGI.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
JavaScript, jQuery, and Mashups Incorporating JavaScript, jQuery, and other Mashups into existing pages.
Dr. Qusai Abuein1 Internet & WWW How to program Chap.(6) JavaScript:Introduction to Scripting.
JavaScript - Basic Concepts Prepared and Presented by Hienvinh Nguyen, Afshin Tiraie.
Scott Marino MSMIS Summer Session Web Site Design and Authoring Session 8 Scott Marino.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
05 – Java Script (1) Informatics Department Parahyangan Catholic University.
1 Chapter 3 – JavaScript Outline Introduction Flowcharts Control Structures if Selection Structure if/else Selection Structure while Repetition Structure.
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
Jaana Holvikivi 1 Introduction to Javascript Jaana Holvikivi Metropolia.
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
CSS Cascading Style Sheets A very brief introduction CSS, Cascading Style Sheets1.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Web Programming Overview. Introduction HTML is limited - it cannot manipulate data How Web pages are extended (include): –Java: an object-oriented programming.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
Understanding JavaScript and Coding Essentials Lesson 8.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Web Programming Java Script-Introduction. What is Javascript? JavaScript is a scripting language using for the Web. JavaScript is a programming language.
Tarik Booker CS 120 California State University, Los Angeles.
Week 1: Introduction to HTML and Web Design
Introduction to CSS: Selectors
Web Basics: HTML/CSS/JavaScript What are they?
Programming Web Pages with JavaScript
Week 3: Introduction to Javascript
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Chapter 6 JavaScript: Introduction to Scripting
Web Development & Design Foundations with HTML5
Week 4: Introduction to Javascript
JavaScript is a programming language designed for Web pages.
Concepts of HTML, CSS and Javascript
Web Development & Design Foundations with HTML5 7th Edition
JavaScript Syntax and Semantics
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
DHTML Javascript Internet Technology.
Your 1st Programming Assignment
DHTML Javascript Internet Technology.
PHP.
T. Jumana Abu Shmais – AOU - Riyadh
Functions, Regular expressions and Events
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Training & Development
JavaScript CS 4640 Programming Languages for Web Applications
Tutorial 10: Programming with javascript
JavaScript Basics What is JavaScript?
PHP an introduction.
Web Programming and Design
Web Programming and Design
Week 5: Recap and Portfolio Site
Web Programming and Design
Web Programming and Design
Introduction to Web programming
JavaScript CS 4640 Programming Languages for Web Applications
Presentation transcript:

Web Programming and Design MPT Senior Cycle Tutor: Tamara Week 3

Plan for the next 4 weeks: Introduction to HTML tags, creating our template file Introduction to CSS and style Introduction to JavaScript More advanced JavaScript Portfolio Site

Web Design Competition There will be a competition for the best designed website!! To enter: Simply upload your website into a folder named “competition” on your Public_html

<tagname>Some Content in here….</tagname> HTML Reminder HTML stands for Hyper Text Markup Language HTML allows us to describe and define the structure of our website using markup All the elements in a web page are represented in tags <tag> Example of HTML elements include: headings, paragraphs, images, videos Nearly all HTML tags come in pairs with an start and end tag <tag> </tag> The Browser will not display these tags, instead it will use the tags to render the web page <tagname>Some Content in here….</tagname> Defines the type of element The stuff that gets displayed Close off the element

h1 {color: blue;} What is CSS? Selector (HTML tag) Property Value CSS stands for Cascading Style Sheets CSS describes how HTML elements are to be displayed on screen It allows us to change the style or appearance of our web page CSS contains a selector and property, value pair The selector is the HTML tag you would like to style h1 {color: blue;} In this example, all the h1 tags in the HTML document will be changed to blue Selector (HTML tag) Property Value

Static vs Dynamic So far we have made webpages using HTML and styled those pages using CSS But these pages are static, as the user cannot interact with them We want to make our websites more Dynamic, so that the user can interact with our webpage

Programming Basics With JavaScript

Where to write our JavaScript Just like CSS, we can write our JavaScript code in more than one place. We can write our JavaScript code in our HTML file, as long as it is contained within <script></script> tags We can also write our code into a separate file with a .js file extension and link it to our HTML in the head

Strings: “Hello MPT Class” Data Types In all programming languages, knowing the data type is very important If you know the data type, you will be able to perform the correct “Operation” There are loads of data types! The most common are numbers, strings, booleans, arrays, objects The ones we will look at today are: Numbers: 1, 2, 3, 4.5, 6.2, 9.3 Strings: “Hello MPT Class” Booleans: True, False

var x = 1; Variables Always finish the line with a ; We can assign a variable to hold a data type value We must be careful with our variable names: Use a meaningful name for your variable, and each variable should have a unique name Never start your variable name with a capital letter, number, or symbol Do not use keywords, or special reserved words for your variable name JavaScript is case sensitive so pay special attention to capital letters and spellings How we create a variable: var x = 1; Always finish the line with a ; We use the keyword var to tell JavaScript we are making a variable Next we make a name for our variable Then we use = to assign a value Then we give a value

var x; x = 1; var a = 4 + 8.5; var b = a - x; Variables You can also declare your variable and assign a value to the variable later on in your code Or your variable can be the value of an expression var x; x = 1; Note: we did not use the word var again. We only need to use var once when declaring a variable Always finish every line with a ; var a = 4 + 8.5; var b = a - x;

Operations Operator Description + Addition - Subtraction * We can perform an operation on these Data Types, just like in arithmetic Operator + - * / % ++ -- Description Addition Subtraction Multiplication Division Modulus Increment Decrement Remainder

Operations Operator Description == equal to === We can also perform comparison operations Operator == === != !== > < >= <= Description equal to equal value and equal type not equal not equal value or not equal type greater than less than greater than or equal to less than or equal to

Operations Operator Description && logical and || logical or We can also use logical operators Operator && || Description logical and logical or

Functions In every programming language, there are predefined functions we can use, and we can write our own functions A predefined function we will use is alert(); alert(); will create an alert box to the website and print a string. But what if we only wanted this alert to happen when the user presses a button?

Functions A function is a block of code This block of code is only triggered when we “Call” our function Like Variables, we can give it a name that we have come up with The function name must be meaningful It should never start with a capital letter, number, or symbol Function names should be unique Be careful of spelling and capital letters

Calling a Function <button> is a new HTML tag We can call a JavaScript Function : When an event occurs (when a user clicks a button) When it is called from JavaScript code Automatically To call a function we simply write the function name followed by ( ) This is an example of a button event calling a function: <button> is a new HTML tag Onclick is the event which happens when the user clicks the button Call to function

JavaScript Events HTML events are "things" that happen to HTML elements. Events can be caused by the user or by the browser. JavaScript can "react" to these events. Event Description onchange An HTML element has been changed onclick The user clicks an HTML element onmouseover The user moves the mouse over an HTML element onmouseout The user moves the mouse away from an HTML element onkeydown The user pushes a keyboard key onload The browser has finished loading the page

function myFunction(argument){ Code goes here…….. } Function Syntax function myFunction(argument){ Code goes here…….. } We have to use the special keyword function Using arguments is optional All code needs to be contained in { }

What will we use JavaScript to do? JavaScript can change all the HTML elements in the page JavaScript can change all the HTML attributes in the page JavaScript can change all the CSS styles in the page JavaScript can remove existing HTML elements and attributes JavaScript can add new HTML elements and attributes JavaScript can react to all existing HTML events in the page JavaScript can create new HTML events in the page

document.getElementById(“idName”) JavaScript DOM To make these changes we use the Document Object Model This allows us to select HTML tags by their id or class name document.getElementById(“idName”) document.getElementsByClassName(“className”)

JavaScript DOM document.getElementById("myH1").style.color = "red"; We can use the DOM model to change style and change the content within HTML tags We can also add HTML to the inside of HTMl tags document.getElementById("myH1").style.color = "red"; document.getElementById(“myH1”).innerHTML = “New Heading”;

JavaScript Scope In JavaScript (and all programming languages) where we create or declare our variable determines its scope Scope means how visible or accessible the variable is to other functions etc There are two types of scope: Global Local

Local Variables Variables declared within a JavaScript function, become LOCAL to the function Local variables have local scope: They can only be accessed within the function For Example:

Global Variables A variable declared outside a function, becomes GLOBAL A global variable has global scope: All scripts and functions on a web page can access it

JavaScript Conditional Sometimes we want to do different actions for different decisions We can use conditional statements in our code to make these decisions In JavaScript we have the following conditional statements: Use if to specify a block of code to be executed, if a specified condition is true Use else to specify a block of code to be executed, if the same condition is false Use else if to specify a new condition to test, if the first condition is false

var myArray = [item1, item2, item3, etc]; What is an Array? Arrays are a way of grouping variables with the same data type together It allows us to save multiple values under one variable name Similar to a list It saves us a lot of lines of code! We separate each value using a comma , var myArray = [item1, item2, item3, etc]; We make an array just like how we make variables We use the [ ] to tell javascript this is an array

var myStrArray = [“HTML”, “CSS”, “JavaScript”]; Array Indexing Once you have created an array, how to access or use one of the values? We do this by array indexing - by writing the variable name and then index number in [ ] TO NOTE: Array indices always start at 0 For example var myStrArray = [“HTML”, “CSS”, “JavaScript”]; alert(myStrArray[0]); alert(myStrArray[1]); alert(myStrArray[2]);

var myStrArray = [“HTML”, “CSS”, “JavaScript”]; Array Indexing With array indexing we can: Make a variable = the array index And replace the value at a certain index var myStrArray = [“HTML”, “CSS”, “JavaScript”]; var myStr = myStrArray[0]; alert(myStr); myStrArray[1] = “StyleSheet”; alert(myStrArray[1]); Assigning new value Replacing value

JavaScript loops JavaScript loops are handy as they let us repeat the same block of code several times Loops are used a lot with arrays There are two types of loop For loop While loop We will focus mainly on the for loop

JavaScript for loop syntax To create a for loop we must use the keyword for Then we setup three statements within ( ) before describing the block of code we want to repeat Statement 1 statement 2 statement 3 all separated by ; for (setup var; condition; increase var){ // block of code to repeat } Keyword for

Important Links https://www.w3schools.com/js/js_operators.asp Data types and operators: https://www.w3schools.com/js/js_operators.asp JavaScript DOM https://www.w3schools.com/js/js_htmldom.asp