JavaScript, Part 2 Instructor: Charles Moen CSCI/CINF 4230.

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 It’s not JAVA. What do these all have in common?
CS 898N – Advanced World Wide Web Technologies Lecture 8: PERL Chin-Chih Chang
Javascript Client-side scripting. Up to now  We've seen a little about how to control  content with HTML  presentation with CSS  Javascript is a language.
Tutorial 10 Programming with JavaScript
Tutorial 14 Working with Forms and Regular Expressions.
CS 299 – Web Programming and Design Overview of JavaScript and DOM Instructor: Dr. Fang (Daisy) Tang.
XP Tutorial 1 New Perspectives on JavaScript, Comprehensive1 Introducing JavaScript Hiding Addresses from Spammers.
Scripting Languages Chapter 8 More About Regular Expressions.
Regular Expressions in ColdFusion Applications Dave Fauth DOMAIN technologies Knowledge Engineering : Systems Integration : Web.
XP Tutorial 14 New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
Last Updated March 2006 Slide 1 Regular Expressions.
Tutorial 14 Working with Forms and Regular Expressions.
Lecture 7: Perl pattern handling features. Pattern Matching Recall =~ is the pattern matching operator A first simple match example print “An methionine.
 Text Manipulation and Data Collection. General Programming Practice Find a string within a text Find a string ‘man’ from a ‘A successful man’
Programming with JavaScript (Chapter 10). XP Various things Midterm grades: Friday Winter Career Fair – Thursday, April 28, 2011 (11 am to 3 pm). – MAC.
Computer Programming for Biologists Class 5 Nov 20 st, 2014 Karsten Hokamp
XHTML Instructor: Charles Moen CSCI/CINF XHTML  A stricter version of HTML  Extensible HTML  The XHTML specification is maintained by the World.
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.
CIS 218 Advanced UNIX1 CIS 218 – Advanced UNIX (g)awk.
JavaScript, Part 3 Instructor: Charles Moen CSCI/CINF 4230.
1 JavaScript in Context. Server-Side Programming.
Tutorial 10 Programming with JavaScript. XP Objectives Learn the history of JavaScript Create a script element Understand basic JavaScript syntax Write.
Tutorial 10 Programming with JavaScript
Done by: Hanadi Muhsen1 Tutorial 1.  Learn the history of JavaScript  Create a script element  Write text to a Web page with JavaScript  Understand.
RegExp. Regular Expression A regular expression is a certain way to describe a pattern of characters. Pattern-matching or keyword search. Regular expressions.
Programming Languages Meeting 13 December 2/3, 2014.
Regular Expressions Regular expressions are a language for string patterns. RegEx is integral to many programming languages:  Perl  Python  Javascript.
DHTML AND JAVASCRIPT Genetic Computer School LESSON 5 INTRODUCTION JAVASCRIPT G H E F.
Regular Expressions in PHP. Supported RE’s The most important set of regex functions start with preg. These functions are a PHP wrapper around the PCRE.
Chapter 9: Perl (continue) Advanced Perl Programming Some materials are taken from Sams Teach Yourself Perl 5 in 21 Days, Second Edition.
REGEX. Problems Have big text file, want to extract data – Phone numbers (503)
Overview A regular expression defines a search pattern for strings. Regular expressions can be used to search, edit and manipulate text. The pattern defined.
Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
When you read a sentence, your mind breaks it into tokens—individual words and punctuation marks that convey meaning. Compilers also perform tokenization.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming regular expressions.
12. Regular Expressions. 2 Motto: I don't play accurately-any one can play accurately- but I play with wonderful expression. As far as the piano is concerned,
CS346 Regular Expressions1 Pattern Matching Regular Expression.
CS 330 Programming Languages 10 / 02 / 2007 Instructor: Michael Eckmann.
CSC 2720 Building Web Applications PHP PERL-Compatible Regular Expressions.
Copyright © Curt Hill Regular Expressions Providing a Search Pattern.
1 Lecture 9 Shell Programming – Command substitution Regular expressions and grep Use of exit, for loop and expr commands COP 3353 Introduction to UNIX.
1 JavaScript in Context. Server-Side Programming.
Unit 11 –Reglar Expressions Instructor: Brent Presley.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming strings.
Regular Expressions /^Hel{2}o\s*World\n$/ SoftUni Team Technical Trainers Software University
LING 408/508: Programming for Linguists Lecture 11 October 5 th.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
IS2802 Introduction to Multimedia Applications for Business Lecture 4: JavaScript, Loops, and Conditional Statements Rob Gleasure
XP Tutorial 7 New Perspectives on JavaScript, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
An Introduction to Regular Expressions Specifying a Pattern that a String must meet.
Javascript Intro Instructor: Shalen Malabon. Lesson Plan Core Javascript Syntax Types and Objects Functions DOM Event Handling Debugging Javascript Smarter.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
OVERVIEW OF CLIENT-SIDE SCRIPTING
CS 330 Programming Languages 09 / 30 / 2008 Instructor: Michael Eckmann.
REEM ALMOTIRI Information Technology Department Majmaah University.
JavaScript and AJAX 2nd Edition Tutorial 1 Programming with JavaScript.
INTERNET APPLICATIONS CPIT405 JavaScript Instructor: Rasha AlOmari
© 2010 Robert K. Moniot1 Chapter 6 Introduction to JavaScript.
CS 330 Class 7 Comments on Exam Programming plan for today:
Chapter 6 JavaScript: Introduction to Scripting
Tutorial 10 Programming with JavaScript
Lecture 9 Shell Programming – Command substitution
Working with Forms and Regular Expressions
Web Systems Development (CSC-215)
WEB PROGRAMMING JavaScript.
Instructor: Charles Moen
Tutorial 10 Programming with JavaScript
Presentation transcript:

JavaScript, Part 2 Instructor: Charles Moen CSCI/CINF 4230

2 Debugging  When programming, add a small amount of code and then refresh the page to test it  When there’s an error, try these techniques Use an alert dialog to output variable values at critical locations and to trace the location of the problem Paste a copy of your code into a backup file, remove all your recent additions, and then add them back, a little at a time Comment out large chunks of code until the problem is removed, then uncomment small chunks until you find the location of the error Paste your code into JSLint at Ask someone else; you might figure it out yourself just by talking about it, or the other person may be able to help Google it JavaScript (Wilcox‏)

3 Debugging  Check the browser’s error console message  With Firefox Check the DOM in Firebug Use console.log("message"); to write to the console Use the Venkman debugger JavaScript (Wilcox‏)

4 JavaScript String Object  When you create a string variable, it is automatically made into a JavaScript String object  length property of the String object The number of characters in the string JavaScript (W3Schools, Koch)‏ var greeting = "Hello World"; alert(greeting.length); //outputs 11

5 String Methods  indexOf() Returns the index of the first character that matches the argument or -1 if it’s not present var greeting = "Hello World"; alert(greeting.indexOf("World")); //outputs 6  charAt() Returns the character at a particular position in a string var greeting = "Hello World"; alert(greeting.charAt(6)); //outputs W JavaScript (W3Schools, Koch)‏

6 String Methods  substring() Extracts a substring from a string Specify the start index, and the index following the end of the substring If there’s no second argument, then the substring continues until the end of the string var greeting = "Hello World"; alert(greeting.substring(6,10)); //outputs Worl alert(greeting.substring(6); //outputs World JavaScript (W3Schools, Koch)‏

7 String Methods  split() Splits a string into an array of strings The argument specifies which character to split on var greeting = "Hello World"; var substrings = greeting.split(" "); for (var i=0; i<substrings.length; i++) { alert(substrings[i]); } //first output is Hello //second output is World JavaScript (W3Schools, Koch)‏

8 String Methods  replace() Replaces some characters with other characters var greeting = "Hello World"; alert(greeting.replace("Hello","Hi")); //output is Hi World JavaScript (W3Schools, Koch)‏  match() Looks for the string in the argument and returns its value, or returns null if it’s not present var greeting = "Hello World"; alert(greeting.match("World")); //outputs World

9 Regular Expressions  A regular expression is a pattern for string matching  A pattern is enclosed between two slashes  We can use a regular expression with a String object’s “match” method JavaScript (W3Schools,Yue, Ding‏) var greeting = "Hello World"; alert(greeting.match(/World/)); //outputs World A regular expression to search for the characters “World”

10 Character Matching  Any character in the regular expression matches itself  A sequence of characters must match the same group  We can also specify a class of characters by using [ ] JavaScript (W3Schools,Yue, Ding‏) /World/ Matches “World” /[abc]/ Matches ‘a’ or ‘b’ or ‘c’ /[a-zA-Z]/ Matches any letter /[^abc]/ Matches any character except ‘a’ or ‘b’ or ‘c’ /a[aeiou]c/ Matches “aac” or “aec” or “aic” or “aoc” or “auc”. Matches any character except \n /a.c/ Matches ‘a’ followed by any character followed by ‘a’

11 Escaped Characters  Characters preceded by a backslash  Invisible characters, certain classes of characters JavaScript (W3Schools,Yue, Ding‏) \n newline \r carriage return \t tab \f formfeed \d A digit [0-9] \D Any character that’s not a digit [^0-9] \w An alphanumeric character [0-9a-zA-Z] \W An non-alphanumeric character [^0-9a-zA-Z] \s A white space [\t\f\r\n] \S A non-white-space character [^\t\f\r\n] \/ A slash

12 Multipliers  Specify how many times a character must occur in the pattern JavaScript (W3Schools,Yue, Ding‏) * 0 or more times + 1 or more times ? 0 or one time {5} Exactly 5 times {3,} 3 or more times {3,6} 3 to 6 times | or /abc|ace/ Matches either “abc” or “ace” /x+y*x+/ Matches one or more ‘x’ followed by 0 or more ‘y’ followed by 1 or more ‘x’

13 Anchors  Align the pattern with a particular part of the string JavaScript (W3Schools,Yue, Ding‏) ^ Matches the beginning of the string $ Matches the end of the string \b Matches on a word boundary \B Matches on a non-word boundary /^abc$/ Matches on “abc” only /^\d+$/ Matches on a string containing only digits /\bHello\b/ Matches “Hello!” but not “HelloThere”

14 Modifiers  Modifiers indicate special options JavaScript (W3Schools,Yue, Ding‏) i Case insensitive g Global m Multiline mode – the ^ and $ match before and after newlines /hello/i Matches “hello” or “HELLO” or “Hello”, etc.

15 Regular Expressions  We can use a regular expression with a String object’s “replace” method JavaScript (W3Schools,Yue, Ding‏) var greeting = "Hello"; alert(greeting.replace(/H/,"J")); //outputs Jello alert(greeting.replace(/l/g,"r")); //outputs Herro

16 References Ding, Wei, “JavaScript” UHCL lecture slides, Keith, Jeremy. DOM Scripting: Web Design with JavaScript and the Document Object Model. friends of ED, Koch, Peter-Paul, PPK on JavaScript. New Riders, Schultz, David and Craig Cook, Beginning HTML with CSS and XHTML: Modern Guide and Reference. Apress, W3Schools Online Web Tutorials. “JavaScript Tutorial”. [Online]. Available: Wilcox, Mike, “Advanced JavaScript Debugging Techniques”. [Online]. Available: techniques/ Yue, Kwok-Bun, “An Introduction to JavaScript” UHCL lecture notes, 2000.