JavaScript.

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
CSCI 6962: Server-side Design and Programming Input Validation and Error Handling.
Ch3: Introduction to HTML5 part 2 Dr. Abdullah Almutairi ISC 340 Fall 2014.
CS 299 – Web Programming and Design Overview of JavaScript and DOM Instructor: Dr. Fang (Daisy) Tang.
Client-Side programming with JavaScript 3
JavaScript Form Validation
CC1003N Week 6 More CSS and Javascript.. Objectives: ● More CSS Examples ● Javascript – introduction ● Uses of Javascript ● Variables ● Comments ● Control.
Objects.  Java Script is an OOP Language  So it allows you to make your own objects and make your own variable types  I will not be going over how.
RegExp. Regular Expression A regular expression is a certain way to describe a pattern of characters. Pattern-matching or keyword search. Regular expressions.
Introduction.  The scripting language most often used for client-side web development.  Influenced by many programming languages, easier for nonprogrammers.
JavaScript Syntax, how to use it in a HTML document
10 – Java Script (3) Informatics Department Parahyangan Catholic University.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
Validation using Regular Expressions. Regular Expression Instead of asking if user input has some particular value, sometimes you want to know if it follows.
INT222 – Internet Fundamentals Week 11: RegExp Object and HTML5 Form Validation 1.
Tutorial 11 1 JavaScript Operators and Expressions.
Text INTRODUCTION TO ASP.NET. InterComm Campaign Guidelines CONFIDENTIAL Simply Server side language Simplified page development model Modular, well-factored,
JavaScript and Ajax (Control Structures) Week 4 Web site:
INTERNET APPLICATIONS CPIT405 JavaScript Instructor: Rasha AlOmari
Client-side (JavaScript) Validation. Associating a function with a click event – Part 1 Use the input tag’s onclick attribute to associate a function.
Web Programming Java Script Core Language Reference.
Java Script Date Object
IS1500: Introduction to Web Development
Chapter 5 Validating Form Data with JavaScript
Build in Objects In JavaScript, almost "everything" is an object.
Java Script Introduction. Java Script Introduction.
>> Introduction to JavaScript
Applied Component I Unit II Introduction of java-script
Web Systems & Technologies
IS1500: Introduction to Web Development
PHP Cookies What is a Cookie?
HTML & teh internets.
Regular Expressions in Perl
JavaScript is a programming language designed for Web pages.
JavaScript - Errors & Exceptions Handling
A little MORE on JavaScript
JavaScript Event Handling.
EXCEPTION HANDLING IN SERVER CLIENT PROGRAMMING
In this session, you will learn about:
Web Technologies PHP 5 Basic Language.
Principles of Software Development
Barb Ericson Georgia Institute of Technology May 2006
PHP Hypertext Preprocessor
SEEM4570 Tutorial 05: JavaScript as OOP
Scope, Objects, Strings, Numbers
Getting User Input with Forms
Javascript Conditionals.
BY: SITI NURBAYA ISMAIL FACULTY of COMPUTER and MATHEMATICAL SCIENCES
CHAPTER 4 CLIENT SIDE SCRIPTING PART 2 OF 3
Web Programming– UFCFB Lecture 17
Error Handling and Validation
BY: SITI NURBAYA ISMAIL FACULTY of COMPUTER and MATHEMATICAL SCIENCES
JavaScript an introduction.
Introduction to JavaScript for Python Programmers
The Internet 12/8/11 JavaScript Review
PHP.
Functions, Regular expressions and Events
2017, Fall Pusan National University Ki-Joune Li
Form Validation (with jQuery, HTML5, and CSS)
BY: SITI NURBAYA ISMAIL FACULTY of COMPUTER and MATHEMATICAL SCIENCES
CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT
Tutorial 10: Programming with javascript
JavaScript Basics What is JavaScript?
JavaScript is a scripting language designed for Web pages by Netscape.
Introduction to Programming
PHP an introduction.
Validation using Regular Expressions
PHP-II.
Programming Basics Review
Presentation transcript:

JavaScript

Java Script Date Object Created with the new Date( ) Methods allow you to get and set the year, month, day, hour, minute, second, and millisecond fields of the object constructor new Date( ) new Date(milliseconds) new Date(datestring) new Date(year,month,date[,hour,minute,second,millisecond ])

JavaScript Form Validation validate the form submitted by the user because it can have inappropriate values can validate name, password, email, date, mobile number etc fields provides you the facility the validate the form on the client side so processing will be fast than server-side validation

Date Objects <html> <body> current time: <p id="time"></p> <script> window.onload=function(){gettime();} function gettime() { var a=new Date(); var h=a.getHours(); var m=a.getMinutes(); var s=a.getSeconds(); m=checktime(m); s=checktime(s); document.getElementById("time").innerHTML=h+":"+m+":"+s; setTimeout(function(){gettime()},1000); } function checktime(i) { if(i<10) i="0"+i; return i; </script> </body> </html>

JavaScript-Regular Expression A regular expression is an object that describes a pattern of characters. used to perform pattern-matching and "search-and-replace" functions on text Syntax /pattern/modifiers; Example var patt = /w3schools/i /w3schools/i  is a regular expression. w3schools  is a pattern (to be used in a search). i  is a modifier (modifies the search to be case-insensitive).

Modifiers perform case-insensitive and global searches Modifier Description i Perform case-insensitive matching g Perform a global match (find all matches rather than stopping after the first match) m Perform multiline matching Brackets used to find a range of characters

Metacharacters

<html> <body> <p>Click the button to do a global search for word characters in a string.</p> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { var str = "Give 100%!"; var patt1 = /\w/g; var result = str.match(patt1); document.getElementById("demo").innerHTML = result; } </script> </body> </html>

JavaScript - Errors & Exceptions Handling Three types of errors in programming: Syntax Errors Runtime Errors Logical Errors try...catch...finally Statement The try statement -test a block of code for errors. The catch statement -handle the error. The throw statement -create custom errors. The finally statement -execute code, after try and catch, regardless of the result.

<html> <head> <script type="text/javascript"> function myFunc() { var a = 100; try { alert("Value of variable a is : " + a ); } catch ( e ) { alert("Error: " + e.description ); </script> </head> <body> <p>Click the following to see the result:</p> <form> <input type="button" value="Click Me" onclick="myFunc();" /> </form> </body> </html>

<script type="text/javascript"> function myFunc() { var a = 100; </head> <body> <p>Click the following to see the result:</p> <form> <input type="button" value="Click Me" onclick="myFunc();" /> </form> </body> </html> <html> <head> <script type="text/javascript"> function myFunc() { var a = 100; var b = 0; try{ if ( b == 0 ){ throw( "Divide by zero error." ); } else var c = a / b; catch ( e ) { alert("Error: " + e ); </script>

JavaScript Form Validation to validate the form submitted by the user validate the form on the client side so processing will be fast than server-side validation.

html> <script> function validateform(){ var name=document.myform.name.value; var password=document.myform.password.value; if (name==null || name==""){ alert("Name can't be blank"); return false; }else if(password.length<6){ alert("Password must be at least 6 characters long."); } </script> <body> <form name="myform" method="post“ onsubmit="return validateform()" > Name: <input type="text" name="name"><br/> Password: <input type="password" name="password"><br/> <input type="submit" value="register"> </form> </body> </html>

<html> <script type="text/javascript"> function matchpass(){ var firstpassword=document.f1.password.value; var secondpassword=document.f1.password2.value; if(firstpassword==secondpassword){ return true; } else{ alert("password must be same!"); return false; </script> <body> <form name="f1" onsubmit="return matchpass()"> Password:<input type="password" name="password" /><br/> Re-enter Password:<input type="password" name="password2"/><br/> <input type="submit"> </form> </body> </html>

JavaScript Built in Objects In JavaScript, almost "everything" is an object. Booleans can be objects (if defined with the new keyword) Numbers can be objects (if defined with the new keyword) Strings can be objects (if defined with the new keyword) Dates are always objects Maths are always objects Regular expressions are always objects Arrays are always objects Functions are always objects Objects are always objects