Web Programming Language

Slides:



Advertisements
Similar presentations
Introducing JavaScript
Advertisements

Intro to JavaScript. JavaScript History Client (generally browser-side) language invented at Netscape under the name LiveScript around 1995 Netscape wanted.
Javascript Introduction Norman White Material is from w3schools.com Go there to run examples interactively.
ALBERT WAVERING BOBBY SENG. Week Whatever: PHP  Announcements/questions/complaints.
SYST Web Technologies SYST Web Technologies Lesson 6 – Intro to JavaScript.
Web Programming Language Week 4 Dr. Ken Cosh Introducing Javascript.
Week 9 PHP Cookies and Session Introduction to JavaScript.
CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad GM-IT CIIT Islamabad CIIT Virtual Campus, CIIT COMSATS Institute.
2440: 211 Interactive Web Programming Expressions & Operators.
1 JavaScript 1. 2 Java vs. JavaScript Java –Is a high level programming language –Is platform independent –Runs on a standardized virtual machine.
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
1 JavaScript in Context. Server-Side Programming.
CHAPTER 4 Java Script อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
Introduction to JavaScript Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 1.
20-753: Fundamentals of Web Programming 1 Lecture 12: Javascript I Fundamentals of Web Programming Lecture 12: Introduction to Javascript.
ALBERT WAVERING BOBBY SENG. Week 4: JavaScript  Quiz  Announcements/questions.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
JavaScript Syntax, how to use it in a HTML document
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
05 – Java Script (1) Informatics Department Parahyangan Catholic University.
JavaScript, Fourth Edition
JavaScript. JavaScript is the programming language of HTML and the Web. Easy to learn One of the 3 languages of all developers MUST learn: 1. HTML to.
CHAPTER 6 Introduction to PHP5 Part I อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
COP 3813 Intro to Internet Computing Prof. Roy Levow Lecture 4 JavaScript.
CST336, Dr. Krzysztof Pietroszek Week 2: PHP. 1.Introduction to PHP 2.Embed PHP code into an HTML web page 3.Generate (output HTML) web page using PHP.
Introduction to JavaScript CSc 2320 Fall 2014 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
This is our seminar JavaScript And DOM This is our seminar JavaScript And DOM.
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
CGS 3066: Web Programming and Design Spring 2016 Introduction to JavaScript.
JAVASCRIPT A quick review. True False ■The DOM is a standardized way of referring to parts of a Web page. ■TRUE ■In the DOM, attributes have their own.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
JavaScript Tutorial. What is JavaScript JavaScript is the programming language of HTML and the Web Programming makes computers do what you want them to.
JavaScript Tutorial First lecture 19/2/2016. Javascript is a dynamic computer programming language. It is lightweight and most commonly used as a part.
© 2010 Robert K. Moniot1 Chapter 6 Introduction to JavaScript.
PHP using MySQL Database for Web Development (part II)
CGS 3066: Web Programming and Design Spring 2017
Build in Objects In JavaScript, almost "everything" is an object.
Java Script Introduction. Java Script Introduction.
>> Introduction to JavaScript
Just enough to get going!
Web Systems & Technologies
Chapter 6 JavaScript: Introduction to Scripting
Tutorial 10 Programming with JavaScript
CHAPTER 5 SERVER SIDE SCRIPTING
Intro to JavaScript CS 1150 Spring 2017.
Exploring JavaScript Ch 14
Introduction to Scripting
JavaScript Syntax and Semantics
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
PHP Introduction.
JavaScript & jQuery Session I
JavaScript and Ajax (Expression and Operators)
JavaScript an introduction.
Web Systems Development (CSC-215)
Exercises on JavaScript & Revision
Your 1st Programming Assignment
WEB PROGRAMMING JavaScript.
PHP.
Tutorial 10 Programming with JavaScript
Web Programming Language
JavaScript CS 4640 Programming Languages for Web Applications
The <script> Tag
PHP an introduction.
Web Programming– UFCFB Lecture 13
Web Programming and Design
Web Programming and Design
JavaScript CS 4640 Programming Languages for Web Applications
Presentation transcript:

Web Programming Language Chapter 8

Introducing JavaScript Variables Operators Control Statements Arrays Functions getElementById() Form Validation Example

JavaScript A VERY important web programming language! To begin with:- “A client side scripting language that is used to bring a webpage to life, running code within the browser and having access to all elements in the document”

Hello World <script type=“text/javascript”> document.write(“Hello World”) </script>

Where to js? Much like css, it is a good idea to move your js to a separate file; <script src=”js/script.js”></script>

JavaScript JavaScript is running on the client machine… <script type=“text/javascript”> document.write(Date()) </script>

JavaScript Variables Weakly Typed Language Any type of data; integers, floating point numbers, strings, characters, arrays, objects… Variable Names – alphanumeric + _ <script type=“text/javascript”> var a = 5; var b = 6; var c = a + b; console.log(c); </script>

JavaScript – Semi Colons Semicolons separate statements, but if you don’t include them, JavaScript will attempt to insert them for you at each new line… <script type=“text/javascript”> var a = 5 var b = 6 var c = a + b console.log(c) </script>

JavaScript var You don’t need to explicitly declare variables using ‘var’. But if you don’t, the variable is essentially global, and may encounter another variable with the same name… Var explicitly declares the variable within a set scope. <script type=“text/javascript”> a = 5 b = 6 c = a + b console.log(c) </script>

JavaScript console The console is a very important tool for developers using JavaScript. Outputting values to the console is very useful for debugging JavaScript code. The console can be accessed through the developer tools in most browsers.

JavaScript Strings Concatenation using + <script type=“text/javascript”> var firstname = “John”; var surname = “Smith”; var fullname = firstname + surname; var name = fullname; console.log(fullname); </script>

JavaScript Strings Can be created using “ or ‘ Quotes can be included in a string using the escape character \ <script type=“text/javascript”> var str1 = “I’m John”; var str2 = ‘I\’m John’; </script>

JavaScript Comments Comment your code!!!! (FFS) Using // Or /*…*/

JavaScript Operators Arithmetic Operators Purpose Notes + Addition -   - Subtraction * Multiplication / Division % Modulus Returns the remainder from a division ++ Increment (add one to the value) Unary operator -- Decrement (minus one from the value)

JavaScript Operators II Assignment Operators Example Equivalent = a = b   += a += b a = a + b -= a -= b a = a – b *= a *= b a = a * b /= a /= b a = a / b %= a %= b a = a % b

JavaScript Operators III Logical Operators Purpose == Equal to != Not equal to <  Less than >  Greater than <= Less than or equal to >= Greater than or equal to === Equal to, both in terms of value and type !== Not equal to, both in terms of value and type && AND || OR ! Not

JavaScript Control Statements WOW!!! <script type=“text/javascript”> if (a > 100) { document.write(“a is greater than 100”); } else if (a<100) { document.write(“a is less than 100”); } else { document.write(“a is 100”); } </script>

JavaScript Control Statements Ternary Operator <script type=“text/javascript”> document.write(a<5 ? “a is less than 5” : “a is not less than 5”); </script>

JavaScript Control Statements Switch! <script type=“text/javascript”> switch(choice) { case 1: document.write(“1 Selected”); break; case 2: document.write(“2 Selected”); break; case default: document.write(“None Selected”); break; } </script>

JavaScript Control Statements For! <script type=“text/javascript”> for(count = 1; count <=5; count++) { document.write(count + “ times 5 is “ + count*5 + “<br>”; } </script>

JavaScript Control Statements While <script type=“text/javascript”> var count = 0; while (count < 5) { document.write(count + “ times 5 is “ + count*5 + “<br>”; count++; } </script>

JavaScript Control Statements Do….While! <script type=“text/javascript”> var count = 0; do { document.write(count + “ times 5 is “ + count*5 + “<br>”; count++; } while (count < 5) </script>

JavaScript Arrays <script type=“text/javascript”> var students = [“John”, “Peter”, “Mark”]; document.write(students[0]); </script>

JavaScript Multidimensional Arrays <script type=“text/javascript”> var students = [["John", 50], ["Peter", 80], ["Mark", 70]]; for(var i=0; i<3; i++) { document.write(students[i][0] + " got " + students[i][1] + "<br>"); } </script>

JavaScript – Associative Arrays <script type=“text/javascript”> countries = {"uk": "United Kingdom", "th": "Thailand", "us": "United States"} for (country in countries) document.write(country + " = " + countries[country] + "<br>") </script>

JavaScript – Accessing the Document The document contains an array of links! The href property of the 1st link on the page would be as follows:- document.links[0].href; You could find out how many links there are on the page as follows:- var numlinks = document.links.length;

JavaScript Functions Break your code into functions! <script type=“text/javascript”> function average(n1, n2, n3) { return (n1+n2+n3)/3; } document.write(average(5,6,7)); </script> But what if there were more than 3 parameters?

JavaScript Functions - arguments Each function contains an arguments object, with an array of parameters sent to the function. <script type=“text/javascript”> function average() { var total = 0; for(index in arguments) { total += arguments[index]; } return total / arguments.length; } document.write(average(5,6,7,8)); </script>

JavaScript Array Functions As well as ‘length’, there are further array functions Function Name Purpose push() Add an element to the end of an array. pop() Remove the last element from the array. reverse() Reverses the order of the array. sort() Sorts the array.

JavaScript – getElementById() A VERY important function! Get elements from the DOM!!! <p id="intro">Hello World</p> <script type="text/javascript"> var el = document.getElementById("intro"); el.style.color = "blue"; </script> Wow!

JavaScript – getElementById() So IMPORTANT – that you hardly ever see it! <script type="text/javascript"> function $(id) { return document.getElementById(id) } </script>

JavaScript – getElementById() It is often aliased by $ <p id="intro">Hello World</p> <script type="text/javascript"> $("intro").style.color = "blue"; </script>

JavaScript - innerHTML innerHTML can return or change the contents of an HTML tag <p id="intro">Hello World</p> <script type="text/javascript"> $("intro").innerHTML = "Goodbye"; </script>

Form Validation In JavaScript! :P