Learning JavaScript. A C P K Siriwardhana, BSc, MSc

Similar documents
JavaScript s role on the Web

What is Java Script? Writing to The HTML Document. What Can JavaScript do? CMPT 165: Java Script

<form>. input elements. </form>

Just add an HTML comment tag <!-- before the first JavaScript statement, and an end-of comment tag --> after the last JavaScript statement, like this:

Introduction to JavaScript

c360 Web Connect Configuration Guide Microsoft Dynamics CRM 2011 compatible c360 Solutions, Inc. c360 Solutions

blink.html 1/1 lectures/6/src/ form.html 1/1 lectures/6/src/

JavaScript Introduction

New Media Production Lecture 7 Javascript

Controlled Assessment Task. Question 1 - Describe how this HTML code produces the form displayed in the browser.

COM1004 Web and Internet Technology

Chapter4: HTML Table and Script page, HTML5 new forms. Asst. Prof. Dr. Supakit Nootyaskool Information Technology, KMITL

Technical Guide Login Page Customization

Enterprise Knowledge Platform Adding the Login Form to Any Web Page

Dynamic Form Processing Tool Version 5.0 November 2014

Exercise 1: Basic HTML and JavaScript

Web Programming/Scripting: JavaScript

HTML Forms IT WS I - Lecture 11

By: JavaScript tutorial-a simple calculator

JavaScript CSCI 201 Principles of Software Development

CITS1231 Web Technologies. JavaScript

1/22/2017. Chapter 2. Functions and Control Structures. Calling Functions. Objectives. Defining Functions (continued) Defining Functions

Session 16. JavaScript Part 1. Reading

Javascript. UNIVERSITY OF MASSACHUSETTS AMHERST CMPSCI 120 Fall 2010

Q1. What is JavaScript?

Javascript. UNIVERSITY OF MASSACHUSETTS AMHERST CMPSCI 120 Fall 2010

Syllabus - July to Sept

Programming Language. Control Structures: Selection (switch) Eng. Anis Nazer First Semester

function makeline(length, ch){ var str = ""; if (length >= 3)

Javascript Lecture 23

Chapter 8. Programming the Web. For the book Mapping in the Cloud Guilford Press Michael P. Peterson

Wed 02 Nov :01:06 AM EST modpow.html

Consider the following file A_Q1.html.

Relational & Logical Operators, if and switch Statements

HTML Tables and Forms. Outline. Review. Review. Example Demo/ Walkthrough. CS 418/518 Web Programming Spring Tables to Display Data"

LAB MANUAL SUBJECT: WEB TECHNOLOGY CLASS : T.E (COMPUTER) SEMESTER: VI

CGS 3066: Spring 2015 JavaScript Reference

1.2 * allow custom user list to be passed in * publish changes to a channel

Client-side Processing

ToDoList. 1.2 * allow custom user list to be passed in * publish changes to a channel ***/

DEV BHOOMI INSTITUTE OF TECHNOLOGY Department of Computer Science and Engineering. Algorithm lab- PCS-553 LAB MANUAL

SmileTiger emeeting Server 2008 Integration Guide

Control Flow. INFO/CSE 100, Spring 2006 Fluency in Information Technology.

Lab 7 Introduction to MySQL

CSC 337. JavaScript Object Notation (JSON) Rick Mercer

1$ 5 ! $ 6 4 * Source: 0 "!*! 0! * 8 97 ?!$ 5 0 *! 4! $ 0 : * ' () 7;7 7<7

By the end of this section of the practical, the students should be able to:

5. An Introduction to JavaScript

Assessment: Course Four Column SPRING / SUMMER 2016

SYBMM ADVANCED COMPUTERS QUESTION BANK 2013

Command-driven, event-driven, and web-based software

Developing Ajax Applications using EWD and Python. Tutorial: Part 2

EXPERIMENT OBJECTIVE:

PHP 5 if...else...elseif Statements

Software. Programming Languages. Types of Software. Types of Languages. Types of Programming. Software does something

LAB Test 1. Rules and Regulations:-

Unit 20 - Client Side Customisation of Web Pages. Week 4 Lesson 5 Fundamentals of Scripting

Introduction to JavaScript, Part 2

HTML forms and the dynamic web

5. JavaScript Basics

Functions. INFO/CSE 100, Spring 2006 Fluency in Information Technology.

M275 - Web Development using PHP and MySQL

Then there are methods ; each method describes an action that can be done to (or with) the object.

1. Variables, Again 2. JavaScript Operators Types 3. Iteration: the for-loop 4. Working with Strings 5. Making Decisions 6.

Client vs Server Scripting

Guide to Integrate. ADSelfService Plus with. Outlook Web App.

Session 6. JavaScript Part 1. Reading

For FreeNAS 0.7 all extensions must meet the following implementation rules (i will check how to block them if they do not do that):

DC71 INTERNET APPLICATIONS DEC 2014

INDIAN SCHOOL DARSAIT FIRST TERM EXAM- MAY 2017 MULTIMEDIA AND WEB TECHNOLOGY (067) SAMPLE PAPER Class: XI Max.Marks: 70

Let's Look Back. We talked about how to create a form in HTML. Forms are one way to interact with users

CSC 551: Web Programming. Spring 2004

Flow Control: Branches and loops

JavaScript. Like PHP, JavaScript is a modern programming language that is derived from the syntax at C.

주소록만들기 주소록. Input 페이지 Edit 페이지 Del 페이지

COPYRIGHT 2012 DROIDLA LIMITED

Assessment - Unit 3 lessons 16-21

Final Examination Semester 1 / Year 2012

Boolean Data-Type. Boolean Data Type (false, true) i.e. 3/6/2018. The type bool is also described as being an integer: bool bflag; bflag = true;

INFO / CSE 100 FINAL EXAM SOLUTIONS March 19, 2009

SCRIPTING, DATABASES, SYSTEM ARCHITECTURE

CGI Programming. What is "CGI"?

The Web: Concepts and Technology

Internet Technologies 5-Dynamic Web. F. Ricci 2010/2011

Practice problems. 1 Draw the output for the following code. 2. Draw the output for the following code.

COMPUTER APPLICATIONS IN BUSINESS FYBMS SEM II

Tutorial. FlexBrowser_Tutorial.doc. FlexBrowser Tutorial 1

HTML, CSS, JavaScript

Hyperlinks, Tables, Forms and Frameworks

Introduction to DHTML

Chapter 2: Functions and Control Structures

PIC 40A. Review for the Final. Copyright 2011 Jukka Virtanen UCLA 1 06/05/15

MULTIMEDIA AND WEB TECHNOLOGY

Programing for Digital Media EE1707. Lecture 3 JavaScript By: A. Mousavi and P. Broomhead SERG, School of Engineering Design, Brunel University, UK

Advanced UI Customization for Microsoft CRM

The Hypertext Markup Language (HTML) Part II. Hamid Zarrabi-Zadeh Web Programming Fall 2013

MI1004 Script programming and internet applications

Lecture 08. Tables in HTML. Mr. Mubashir Ali Lecturer (Dept. of Computer Science)

Marking Scheme Multimedia and Web Technology Class: XII Session

Introduction to Computer Science (I1100) Internet. Chapter 7

Transcription:

Learning JavaScript A C P K Siriwardhana, BSc, MSc

Condition Statements If statements loop statements switch statement

IF THEN ELSE If something is true, take a specified action. If false, take some other action (including doing nothing). INCREMENT (DECREMENT) A special type of assignment statement, such as x=x+1. INITIALIZE A special kind of assignment statement used to set initial values in a program. LOOP (conditions) END LOOP Execute instructions repeatedly until (or as long as) certain conditions are met.

if (condition) code to be executed if condition is true

<html><head><title>my Page</title></head> <script type="text/javascript"> var d = new Date() var time = d.gethours() if (time < 12) document.write("<b>good morning</b>") </script> <p>this example demonstrates the If statement.</p> <p>if the time on your browser is less than 12,you will get a "Good morning" greeting.</p> </body> </html>

if (condition) code to be executed if condition is true Else code to be executed if condition is false

<html><head><title>my Page</title></head> <body> <script type="text/javascript"> var d = new Date() var time = d.gethours() if (time < 12) document.write("<b>good Morning</b>") else document.write("<b>good Day</b>") </script> <p>this example demonstrates the If...Else statement.</p> <p>if the time on your browser is less than 12,you will get a "Good Morning" greeting. Otherwise you will get a "Good Day" greeting.</p> </body> </html>

<html><head><title>my Page</title> <script type="text/javascript"> function ifclosed() document.write("mywindow has been closed!"); function ifnotclosed()document.write("mywindow has not been closed!"); function checkwin() if (mywindow.closed) ifclosed(); else ifnotclosed(); </script> </head> <body> <script type="text/javascript"> mywindow = window.open('','','width=200,height=100'); mywindow.document.write("this is 'mywindow'"); </script> <input type="button" value="has 'mywindow' been closed?" onclick="checkwin()" /> </body> </html>

if (condition1) code to be executed if condition1 is true Else if (condition2) code to be executed if condition2 is true Else code to be executed if all condition are false

<html><head><title>my Page</title> <script language="javascript"> function FindGrade() var valmarks = parseint(document.getelementbyid("marks").value); if (valmarks>70) gradevalue = "A"????????????????????????????????? document.getelementbyid("grade").value = gradevalue; </script> </head> <body> <form> <input type="text" name="marks" id="marks" value = " " > <input type="button" value="sub" onclick=" FindGrade();"> <input type="text" name=" grade " id="grade" value = " " > </form> </body> </html>

<html><head><title>my Page</title> <script language="javascript"> function FindGrade() var valmarks = parseint(document.getelementbyid("marks").value); if (valmarks>70) gradevalue = "A" else if(valmarks>60) gradevalue = "B" else if(valmarks>50) gradevalue = "C" else if(valmarks>40) gradevalue = "D" else if(valmarks>30) gradevalue = "E" else gradevalue = "F" document.getelementbyid("grade").value = gradevalue; </script> </head> <body> <form> <input type="text" name="marks" id="marks" value = " " > <input type="button" value="sub" onclick=" FindGrade();"> <input type="text" name=" grade " id="grade" value = " " > </form> </body> </html>

JavaScript comparators There are several operators used for making comparisons between variables The main arithmetic comparators are: == equal < less than <= less than or equal to > greater than >= greater than or equal to!= not equal to

JavaScript Logic When making comparison you can also use logic functions &&! and or (that s two pipes ; shift backslash) not Eg: if (age > 18 && age < 60) status = Adults ; else status = Young or very old ;

JavaScript Logic <html><head><title>my Page</title> <script type="text/javascript"> function Findage() var age = parseint(document.getelementbyid("myage").value); if (age > 18 && age < 60) document.write("<b> Adults!</b>"); else document.write("<b> Young or very old!</b>"); </script> </head> <body><form> <input type="text" name="myage" id="myage" value = " " > <input type="button" value="sub" onclick=" Findage();"> </form> </body> </html>

<html><head><title>my Page</title></head> <body> <script type="text/javascript"> var now = new Date(); var hour = now.gethours(); if (hour > 5 && hour <= 12) document.write("<b>good Morning!</b>"); else if (hour > 12 && hour <= 17) document.write("<b>good Afternoon!</b>"); else document.write("<b>good Evening!</b>"); </script> </body> </html>

JavaScript Form Validation <html><head><title>my Page</title> <script type="text/javascript"> function validateform() if(document.getelementbyid("username").value == '') alert('please enter Username'); document.getelementbyid("username").focus(); return(false); if(document.getelementbyid("password").value == '') alert('please enter Password'); document.getelementbyid("password").focus(); return(false); return(true); </script> <body>

JavaScript Form Validation <body> <form action="" onsubmit="return validateform()"> <table width="400" border="0" cellspacing="0" cellpadding="0"> <tr> <td>user Name</td> <td> <input name="username" type="text" id="username" class="" > </td> </tr> <tr> <td>password</td> <td> <input name="password" type="text" id="password" class="" > </td> </tr> <tr> <td> </td> <td> <input type="submit" name="sub" value="submit " id="sub" > </td> </tr> </table> </form> </body> </html>

The JavaScript Switch Statement Use the switch statement to select one of many blocks of code to be executed. <html><head><title>my Page</title></head> <body> <script type="text/javascript"> var d=new Date(); var theday=d.getday(); switch (theday) case 4: document.write("<b> Thursday </b>"); break; case 6: document.write("<b>super Saturday</b>"); break; case 0: document.write("<b>sleepy Sunday</b>"); break; default: document.write("<b>i'm really looking forward to this weekend!</b>"); </script> <p>this JavaScript will generate a different greeting based on what day it is. Note that Sunday=0, Monday=1, Tuesday=2, etc.</p> </body></html>